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

项目:lams    文件:JoinWalker.java   
/**
 * Generate a sequence of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
 */
protected final JoinFragment mergeOuterJoins(List associations)
throws MappingException {
    JoinFragment outerjoin = getDialect().createOuterJoinFragment();
    Iterator iter = associations.iterator();
    OuterJoinableAssociation last = null;
    while ( iter.hasNext() ) {
        OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
        if ( last != null && last.isManyToManyWith( oj ) ) {
            oj.addManyToManyJoin( outerjoin, ( QueryableCollection ) last.getJoinable() );
        }
        else {
            oj.addJoins(outerjoin);
        }
        last = oj;
    }
    last = null;
    return outerjoin;
}
项目:lams    文件:OuterJoinableAssociation.java   
public void addManyToManyJoin(JoinFragment outerjoin, QueryableCollection collection) throws MappingException {
    String manyToManyFilter = collection.getManyToManyFilterFragment( rhsAlias, enabledFilters );
    String condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on )
                    ? manyToManyFilter
                    : on + " and " + manyToManyFilter;
    outerjoin.addJoin(
            joinable.getTableName(),
            rhsAlias,
            lhsColumns,
            rhsColumns,
            joinType,
            condition
    );
    outerjoin.addJoins(
        joinable.fromJoinFragment(rhsAlias, false, true),
        joinable.whereJoinFragment(rhsAlias, false, true)
    );
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
private void renderJoin(Join join, JoinFragment joinFragment) {
    if ( CompositeQuerySpace.class.isInstance( join.getRightHandSide() ) ) {
        handleCompositeJoin( join, joinFragment );
    }
    else if ( EntityQuerySpace.class.isInstance( join.getRightHandSide() ) ) {
        // do not render the entity join for a one-to-many association, since the collection join
        // already joins to the associated entity table (see doc in renderCollectionJoin()).
        if ( join.getLeftHandSide().getDisposition() == QuerySpace.Disposition.COLLECTION ) {
            if ( CollectionQuerySpace.class.cast( join.getLeftHandSide() ).getCollectionPersister().isManyToMany() ) {
                renderManyToManyJoin( join, joinFragment );
            }
            else if ( JoinDefinedByMetadata.class.isInstance( join ) &&
                    CollectionPropertyNames.COLLECTION_INDICES.equals( JoinDefinedByMetadata.class.cast( join ).getJoinedPropertyName() ) ) {
                renderManyToManyJoin( join, joinFragment );
            }
        }
        else {
            renderEntityJoin( join, joinFragment );
        }
    }
    else if ( CollectionQuerySpace.class.isInstance( join.getRightHandSide() ) ) {
        renderCollectionJoin( join, joinFragment );
    }
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
private void renderEntityJoin(Join join, JoinFragment joinFragment) {
    final EntityQuerySpace rightHandSide = (EntityQuerySpace) join.getRightHandSide();

    // see if there is already aliases registered for this entity query space (collection joins)
    EntityReferenceAliases aliases = aliasResolutionContext.resolveEntityReferenceAliases( rightHandSide.getUid() );
    if ( aliases == null ) {
        aliasResolutionContext.generateEntityReferenceAliases(
                rightHandSide.getUid(),
                rightHandSide.getEntityPersister()
        );
    }

    final Joinable joinable = (Joinable) rightHandSide.getEntityPersister();
    addJoins(
            join,
            joinFragment,
            joinable
    );
}
项目: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;
}
项目:ephesoft    文件:BatchClassDynamicPluginConfigDaoImpl.java   
/**
 * To get Dynamic Plugin Properties for Batch Class.
 * 
 * @param batchClassIdentifier String
 * @param pluginName String
 * @param pluginProperty PluginProperty
 * @return List<BatchClassDynamicPluginConfig>
 */
@Override
public List<BatchClassDynamicPluginConfig> getDynamicPluginPropertiesForBatchClass(String batchClassIdentifier, String pluginName,
        PluginProperty pluginProperty) {

    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE, JoinFragment.INNER_JOIN);
    criteria.createAlias("batchClassPlugin.batchClassModule.batchClass", BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.createAlias("batchClassPlugin.plugin", "plugin", JoinFragment.INNER_JOIN);
    criteria.createAlias("batchClassPlugin.batchClassDynamicPluginConfigs", "batchClassDynamicPluginConfigs",
            JoinFragment.INNER_JOIN);
    if (pluginProperty != null) {
        criteria.add(Restrictions.eq("batchClassDynamicPluginConfigs.name", pluginProperty.getPropertyKey()));
    }
    criteria.add(Restrictions.eq("plugin.pluginName", pluginName));
    criteria.add(Restrictions.eq("batchClass.identifier", batchClassIdentifier));
    return find(criteria);
}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to fetch all Field types by document type name.
 * 
 * @param docTypeName String
 * @param batchInstanceIdentifierIdentifier String
 * @return List<FieldType>
 */
@Override
public List<FieldType> getFdTypeByDocTypeNameForBatchInstance(String docTypeName, String batchInstanceIdentifier) {

    LOG.info("batchInstanceID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));

    return find(criteria);

}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to get field type for a batch for a particular document.
 *  
 * @param fieldTypeName String
 * @param docTypeName String
 * @param batchInstanceIdentifier String
 * @return FieldType
 */
@Override
public FieldType getFieldType(String fieldTypeName, String docTypeName, String batchInstanceIdentifier) {

    LOG.info("batchInstanceID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(NAME, fieldTypeName));
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));

    return findSingle(criteria);

}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to fetch all Field types by document type name.
 * 
 * @param docTypeName String
 * @param batchInstanceIdentifier String
 * @param isKVExtraction boolean
 * @return List<FieldType>
 */
@Override
public List<FieldType> getFdTypeByDocumentTypeName(String docTypeName, String batchInstanceIdentifier, boolean isKVExtraction) {
    LOG.info("batchInstanceID ID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);

    if (isKVExtraction) {
        criteria.setFetchMode("kvExtraction", FetchMode.JOIN);
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    }

    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));
    return find(criteria);
}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to fetch all Field types by document type name.
 * 
 * @param docTypeName String
 * @param batchInstanceIdentifier String
 * @return List<FieldType>
 */
@Override
public List<FieldType> getFdTypeAndRegexValidationByDocTypeName(String docTypeName, String batchInstanceIdentifier) {

    LOG.info("batchInstanceID ID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);

    criteria.setFetchMode(REGEX_VALIDATION, FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));

    return find(criteria);

}
项目:ephesoft    文件:BatchInstanceDaoImpl.java   
/**
 * API to fetch all unfinished batch instances.
 * 
 * @param uncFolder String
 * @return List<BatchInstance>
 */
@Override
public List<BatchInstance> getAllUnFinishedBatchInstances(String uncFolder) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq("batchClass.uncFolder", uncFolder));

    List<BatchInstanceStatus> statusList = new ArrayList<BatchInstanceStatus>();
    statusList.add(BatchInstanceStatus.NEW);
    statusList.add(BatchInstanceStatus.ERROR);
    statusList.add(BatchInstanceStatus.READY_FOR_REVIEW);
    statusList.add(BatchInstanceStatus.READY_FOR_VALIDATION);
    statusList.add(BatchInstanceStatus.RUNNING);
    statusList.add(BatchInstanceStatus.READY);
    statusList.add(BatchInstanceStatus.RESTART_IN_PROGRESS);
    statusList.add(BatchInstanceStatus.LOCKED);
    criteria.add(Restrictions.in(STATUS, statusList));

    return find(criteria);
}
项目:ephesoft    文件:BatchInstanceDaoImpl.java   
/**
 * API to fetch whether the batch class has any of its batches under processing i.e. not finished.
 * 
 * @param batchClassIdentifier {@link String}
 * @return int, count of batch instances
 */
@Override
public int getAllUnFinishedBatchInstancesCount(String batchClassIdentifier) {
    EphesoftCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(BATCH_CLASS_IDENTIFIER, batchClassIdentifier));

    List<BatchInstanceStatus> statusList = new ArrayList<BatchInstanceStatus>();
    statusList.add(BatchInstanceStatus.NEW);
    statusList.add(BatchInstanceStatus.ERROR);
    statusList.add(BatchInstanceStatus.READY_FOR_REVIEW);
    statusList.add(BatchInstanceStatus.READY_FOR_VALIDATION);
    statusList.add(BatchInstanceStatus.RUNNING);
    statusList.add(BatchInstanceStatus.READY);
    statusList.add(BatchInstanceStatus.RESTART_IN_PROGRESS);
    statusList.add(BatchInstanceStatus.LOCKED);
    statusList.add(BatchInstanceStatus.REMOTE);
    criteria.add(Restrictions.in(STATUS, statusList));
    return count(criteria);
}
项目:ephesoft    文件:PageTypeDaoImpl.java   
/**
 * An API to fetch page type by page type name.
 * 
 * @param name String
 * @param batchInstanceIdentifier String
 * @return List<PageType>
 */
@Override
public List<PageType> getPageTypeByName(String name, String batchInstanceIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(NAME, name));
    if (null != batchInstanceIdentifier) {
        criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
        criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
        DetachedCriteria subQuery = criteria(BatchInstance.class);
        subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
        subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
        subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
        criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    }
    return find(criteria);
}
项目:ephesoft    文件:BatchClassPluginConfigDaoImpl.java   
/**
 * API to get plugin properties for Batch.
 * 
 * @param batchInstanceIdentifier {@link String}
 * @param pluginName {@link String}
 * @return List<BatchClassPluginConfig> 
 */
@Override
public List<BatchClassPluginConfig> getPluginPropertiesForBatch(String batchInstanceIdentifier, String pluginName) {

    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE_BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_PLUGIN, PLUGIN, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(PLUGIN_PLUGIN_NAME, pluginName));
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq("identifier", batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, "batchClass1", JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property("batchClass1.identifier"));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS_IDENTIFIER, subQuery));
    return find(criteria);

}
项目:ephesoft    文件:BatchClassPluginConfigDaoImpl.java   
/**
 * API to get plugin properties for Batch class.
 * 
 * @param batchClassIdentifier {@link String}
 * @param pluginName {@link String}
 * @param pluginProperty {@link PluginProperty}
 * @return List<BatchClassPluginConfig> 
 */
@Override
public List<BatchClassPluginConfig> getPluginPropertiesForBatchClass(String batchClassIdentifier, String pluginName,
        PluginProperty pluginProperty) {

    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE_BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_PLUGIN, PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_PLUGIN_CONFIGS, BATCH_CLASS_PLUGIN_CONFIGS, JoinFragment.INNER_JOIN);
    if (pluginProperty != null) {
        criteria.add(Restrictions.eq("batchClassPluginConfigs.name", pluginProperty.getPropertyKey()));
    }
    criteria.add(Restrictions.eq(PLUGIN_PLUGIN_NAME, pluginName));
    criteria.add(Restrictions.eq(BATCH_CLASS_IDENTIFIER, batchClassIdentifier));
    return find(criteria);
}
项目:ephesoft    文件:BatchClassPluginConfigDaoImpl.java   
/**
 * API to get all plugin properties for Batch class by qualifier.
 * 
 * @param batchClassIdentifier {@link String}
 * @param pluginName {@link String}
 * @param qualifier {@link String}
 * @return List<BatchClassPluginConfig> 
 */
@Override
public List<BatchClassPluginConfig> getAllPluginPropertiesForBatchClassByQualifier(String batchClassIdentifier,
        String pluginName, String qualifier) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE_BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_PLUGIN, PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_PLUGIN_CONFIGS, BATCH_CLASS_PLUGIN_CONFIGS, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(PLUGIN_PLUGIN_NAME, pluginName));
    if (qualifier != null) {
        criteria.add(Restrictions.eq("batchClassPluginConfigs.qualifier", qualifier));
    }
    criteria.add(Restrictions.eq(BATCH_CLASS_IDENTIFIER, batchClassIdentifier));
    return find(criteria);
}
项目:cacheonix-core    文件:AbstractEntityJoinWalker.java   
protected final void initAll(
    final String whereString,
    final String orderByString,
    final LockMode lockMode)
throws MappingException {

    walkEntityTree( persister, getAlias() );

    List allAssociations = new ArrayList();
    allAssociations.addAll(associations);
    allAssociations.add( new OuterJoinableAssociation(
            persister.getEntityType(),
            null,
            null,
            alias,
            JoinFragment.LEFT_OUTER_JOIN,
            getFactory(),
            CollectionHelper.EMPTY_MAP
        ) );

    initPersisters(allAssociations, lockMode);
    initStatementString( whereString, orderByString, lockMode);
}
项目:cacheonix-core    文件:JoinWalker.java   
/**
 * Should we join this association?
 */
protected boolean isJoinable(
    final int joinType,
    final Set visitedAssociationKeys, 
    final String lhsTable,
    final String[] lhsColumnNames,
    final AssociationType type,
    final int depth
) {
    if (joinType<0) return false;

    if (joinType==JoinFragment.INNER_JOIN) return true;

    Integer maxFetchDepth = getFactory().getSettings().getMaximumFetchDepth();
    final boolean tooDeep = maxFetchDepth!=null && 
        depth >= maxFetchDepth.intValue();

    return !tooDeep && !isDuplicateAssociation(lhsTable, lhsColumnNames, type);
}
项目:cacheonix-core    文件:JoinWalker.java   
/**
 * Generate a sequence of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
 */
protected final JoinFragment mergeOuterJoins(List associations)
throws MappingException {
    JoinFragment outerjoin = getDialect().createOuterJoinFragment();
    Iterator iter = associations.iterator();
    OuterJoinableAssociation last = null;
    while ( iter.hasNext() ) {
        OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
        if ( last != null && last.isManyToManyWith( oj ) ) {
            oj.addManyToManyJoin( outerjoin, ( QueryableCollection ) last.getJoinable() );
        }
        else {
            oj.addJoins(outerjoin);
        }
        last = oj;
    }
    last = null;
    return outerjoin;
}
项目:cacheonix-core    文件:OuterJoinableAssociation.java   
public void addManyToManyJoin(JoinFragment outerjoin, QueryableCollection collection) throws MappingException {
    String manyToManyFilter = collection.getManyToManyFilterFragment( rhsAlias, enabledFilters );
    String condition = "".equals( manyToManyFilter )
            ? on
            : "".equals( on )
                    ? manyToManyFilter
                    : on + " and " + manyToManyFilter;
    outerjoin.addJoin(
            joinable.getTableName(),
            rhsAlias,
            lhsColumns,
            rhsColumns,
            joinType,
            condition
    );
    outerjoin.addJoins(
        joinable.fromJoinFragment(rhsAlias, false, true),
        joinable.whereJoinFragment(rhsAlias, false, true)
    );
}
项目:cacheonix-core    文件:AbstractEntityPersister.java   
protected JoinFragment createJoin(String name, boolean innerJoin, boolean includeSubclasses) {
    final String[] idCols = StringHelper.qualify( name, getIdentifierColumnNames() ); //all joins join to the pk of the driving table
    final JoinFragment join = getFactory().getDialect().createOuterJoinFragment();
    final int tableSpan = getSubclassTableSpan();
    for ( int j = 1; j < tableSpan; j++ ) { //notice that we skip the first table; it is the driving table!
        final boolean joinIsIncluded = isClassOrSuperclassTable( j ) ||
                ( includeSubclasses && !isSubclassTableSequentialSelect( j ) && !isSubclassTableLazy( j ) );
        if ( joinIsIncluded ) {
            join.addJoin( getSubclassTableName( j ),
                    generateTableAlias( name, j ),
                    idCols,
                    getSubclassTableKeyColumns( j ),
                    innerJoin && isClassOrSuperclassTable( j ) && !isInverseTable( j ) && !isNullableTable( j ) ?
                    JoinFragment.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there)
                    JoinFragment.LEFT_OUTER_JOIN //we can never inner join to subclass tables
                );
        }
    }
    return join;
}
项目:cacheonix-core    文件:HqlSqlWalker.java   
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() ) {
        log.debug( "createFromFilterElement() : processed filter FROM element." );
    }
    return fromElement;
}
项目:cacheonix-core    文件:CollectionSubqueryFactory.java   
public static String createCollectionSubquery(
        JoinSequence joinSequence,
        Map enabledFilters,
        String[] columns) {
    try {
        JoinFragment join = joinSequence.toJoinFragment( enabledFilters, true );
        return new StringBuffer( "select " )
                .append( StringHelper.join( ", ", columns ) )
                .append( " from " )
                .append( join.toFromFragmentString().substring( 2 ) )// remove initial ", "
                .append( " where " )
                .append( join.toWhereFragmentString().substring( 5 ) )// remove initial " and "
                .toString();
    }
    catch ( MappingException me ) {
        throw new QueryException( me );
    }
}
项目:lams    文件:AbstractEntityJoinWalker.java   
private void initStatementString(
        final String projection,
        final String condition,
        final String orderBy,
        final String groupBy,
        final LockOptions lockOptions) throws MappingException {

    final int joins = countEntityPersisters( associations );
    suffixes = BasicLoader.generateSuffixes( joins + 1 );

    JoinFragment ojf = mergeOuterJoins( associations );

    Select select = new Select( getDialect() )
            .setLockOptions( lockOptions )
            .setSelectClause(
                    projection == null ?
                            persister.selectFragment( alias, suffixes[joins] ) + selectString( associations ) :
                            projection
            )
            .setFromClause(
                    getDialect().appendLockHint( lockOptions, persister.fromTableFragment( alias ) ) +
                            persister.fromJoinFragment( alias, true, true )
            )
            .setWhereClause( condition )
            .setOuterJoins(
                    ojf.toFromFragmentString(),
                    ojf.toWhereFragmentString() + getWhereFragment()
            )
            .setOrderByClause( orderBy( associations, orderBy ) )
            .setGroupByClause( groupBy );

    if ( getFactory().getSettings().isCommentsEnabled() ) {
        select.setComment( getComment() );
    }
    sql = select.toStatementString();
}
项目:lams    文件:OuterJoinableAssociation.java   
public void addJoins(JoinFragment outerjoin) throws MappingException {
    outerjoin.addJoin(
        joinable.getTableName(),
        rhsAlias,
        lhsColumns,
        rhsColumns,
        joinType,
        on
    );
    outerjoin.addJoins(
        joinable.fromJoinFragment(rhsAlias, false, true),
        joinable.whereJoinFragment(rhsAlias, false, true)
    );
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
public void processQuerySpaceJoins(QuerySpace querySpace, SelectStatementBuilder selectStatementBuilder) {
    LOG.debug( "processing queryspace " + querySpace.getUid() );
    final JoinFragment joinFragment = factory.getDialect().createOuterJoinFragment();
    processQuerySpaceJoins( querySpace, joinFragment );

    selectStatementBuilder.setOuterJoins(
            joinFragment.toFromFragmentString(),
            joinFragment.toWhereFragmentString()
    );
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
private void processQuerySpaceJoins(QuerySpace querySpace, JoinFragment joinFragment) {
    // IMPL NOTES:
    //
    // 1) The querySpace and the left-hand-side of each of the querySpace's joins should really be the same.
    // validate that?  any cases where they wont be the same?
    //
    // 2) Assume that the table fragments for the left-hand-side have already been rendered.  We just need to
    // figure out the proper lhs table alias to use and the column/formula from the lhs to define the join
    // condition, which can be different per Join

    for ( Join join : querySpace.getJoins() ) {
        processQuerySpaceJoin( join, joinFragment );
    }
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
private void handleCompositeJoin(Join join, JoinFragment joinFragment) {
    final String leftHandSideUid = join.getLeftHandSide().getUid();
    final String rightHandSideUid = join.getRightHandSide().getUid();

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

    aliasResolutionContext.registerCompositeQuerySpaceUidResolution( rightHandSideUid, leftHandSideTableAlias );
}
项目: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 )
    );
}
项目:lams    文件:LoadQueryJoinAndFetchProcessor.java   
private void renderManyToManyJoin(
        Join join,
        JoinFragment joinFragment) {

    // for many-to-many we have 3 table aliases.  By way of example, consider a normal m-n: User<->Role
    // where User is the FetchOwner and Role (User.roles) is the Fetch.  We'd have:
    //      1) the owner's table : user - in terms of rendering the joins (not the fetch select fragments), the
    //          lhs table alias is only needed to qualify the lhs join columns, but we already have the qualified
    //          columns here (aliasedLhsColumnNames)
    //final String ownerTableAlias = ...;
    //      2) the m-n table : user_role
    //      3) the element table : role
    final EntityPersister entityPersister = ( (EntityQuerySpace) join.getRightHandSide() ).getEntityPersister();
    final String entityTableAlias = aliasResolutionContext.resolveSqlTableAliasFromQuerySpaceUid(
        join.getRightHandSide().getUid()
    );

    if ( StringHelper.isEmpty( entityTableAlias ) ) {
        throw new IllegalStateException( "Collection element (many-to-many) table alias cannot be empty" );
    }
    if ( JoinDefinedByMetadata.class.isInstance( join ) &&
            CollectionPropertyNames.COLLECTION_ELEMENTS.equals( ( (JoinDefinedByMetadata) join ).getJoinedPropertyName() ) ) {
        final CollectionQuerySpace leftHandSide = (CollectionQuerySpace) join.getLeftHandSide();
        final CollectionPersister persister = leftHandSide.getCollectionPersister();
        final String manyToManyFilter = persister.getManyToManyFilterFragment(
                entityTableAlias,
                buildingParameters.getQueryInfluencers().getEnabledFilters()
        );
        joinFragment.addCondition( manyToManyFilter );
    }

    addJoins(
            join,
            joinFragment,
            (Joinable) entityPersister
    );
}
项目:lams    文件:AbstractEntityPersister.java   
protected String renderSelect(
        final int[] tableNumbers,
        final int[] columnNumbers,
        final int[] formulaNumbers) {

    Arrays.sort( tableNumbers ); //get 'em in the right order (not that it really matters)

    //render the where and from parts
    int drivingTable = tableNumbers[0];
    final String drivingAlias = generateTableAlias( getRootAlias(), drivingTable ); //we *could* regerate this inside each called method!
    final String where = createWhereByKey( drivingTable, drivingAlias );
    final String from = createFrom( drivingTable, drivingAlias );

    //now render the joins
    JoinFragment jf = createJoin( tableNumbers, drivingAlias );

    //now render the select clause
    SelectFragment selectFragment = createSelect( columnNumbers, formulaNumbers );

    //now tie it all together
    Select select = new Select( getFactory().getDialect() );
    select.setSelectClause( selectFragment.toFragmentString().substring( 2 ) );
    select.setFromClause( from );
    select.setWhereClause( where );
    select.setOuterJoins( jf.toFromFragmentString(), jf.toWhereFragmentString() );
    if ( getFactory().getSettings().isCommentsEnabled() ) {
        select.setComment( "sequential select " + getEntityName() );
    }
    return select.toStatementString();
}
项目:lams    文件:JoinSequence.java   
private void addSubclassJoins(
        JoinFragment joinFragment,
        String alias,
        Joinable joinable,
        boolean innerJoin,
        boolean includeSubclassJoins,
        Set<String> treatAsDeclarations) {
    final boolean include = includeSubclassJoins && isIncluded( alias );
    joinFragment.addJoins(
            joinable.fromJoinFragment( alias, innerJoin, include, treatAsDeclarations ),
            joinable.whereJoinFragment( alias, innerJoin, include, treatAsDeclarations )
    );
}
项目:lams    文件:JoinProcessor.java   
private void addJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement) {
    JoinFragment joinFragment = join.toJoinFragment(
            walker.getEnabledFilters(),
            fromElement.useFromFragment() || fromElement.isDereferencedBySuperclassOrSubclassProperty(),
            fromElement.getWithClauseFragment(),
            fromElement.getWithClauseJoinAlias()
    );

    String frag = joinFragment.toFromFragmentString();
    String whereFrag = joinFragment.toWhereFragmentString();

    // If the from element represents a JOIN_FRAGMENT and it is
    // a theta-style join, convert its type from JOIN_FRAGMENT
    // to FROM_FRAGMENT
    if ( fromElement.getType() == JOIN_FRAGMENT &&
            ( join.isThetaStyle() || StringHelper.isNotEmpty( whereFrag ) ) ) {
        fromElement.setType( FROM_FRAGMENT );
        fromElement.getJoinSequence().setUseThetaStyle( true ); // this is used during SqlGenerator processing
    }

    // If there is a FROM fragment and the FROM element is an explicit, then add the from part.
    if ( fromElement.useFromFragment() /*&& StringHelper.isNotEmpty( frag )*/ ) {
        String fromFragment = processFromFragment( frag, join ).trim();
        LOG.debugf( "Using FROM fragment [%s]", fromFragment );
        processDynamicFilterParameters(
                fromFragment,
                fromElement,
                walker
        );
    }

    syntheticAndFactory.addWhereFragment(
            joinFragment,
            whereFrag,
            query,
            fromElement,
            walker
    );
}
项目:lams    文件:CollectionSubqueryFactory.java   
public static String createCollectionSubquery(
        JoinSequence joinSequence,
        Map enabledFilters,
        String[] columns) {
    try {
        JoinFragment join = joinSequence.toJoinFragment( enabledFilters, true );
        return "select " + StringHelper.join( ", ", columns )
                + " from " + join.toFromFragmentString().substring( 2 )
                + " where " + join.toWhereFragmentString().substring( 5 );
    }
    catch (MappingException me) {
        throw new QueryException( me );
    }
}
项目:lams    文件:QueryTranslatorImpl.java   
private void mergeJoins(JoinFragment ojf) throws MappingException, QueryException {

        Iterator iter = joins.entrySet().iterator();
        while ( iter.hasNext() ) {
            Map.Entry me = ( Map.Entry ) iter.next();
            String name = ( String ) me.getKey();
            JoinSequence join = ( JoinSequence ) me.getValue();
            join.setSelector( new JoinSequence.Selector() {
                public boolean includeSubclasses(String alias) {
                    boolean include = returnedTypes.contains( alias ) && !isShallowQuery();
                    return include;
                }
            } );

            if ( typeMap.containsKey( name ) ) {
                ojf.addFragment( join.toJoinFragment( enabledFilters, true ) );
            }
            else if ( collections.containsKey( name ) ) {
                ojf.addFragment( join.toJoinFragment( enabledFilters, true ) );
            }
            else {
                //name from a super query (a bit inelegant that it shows up here)
            }

        }

    }
项目:ephesoft    文件:BatchClassEmailConfigDaoImpl.java   
/**
 * An api to fetch all Email configurations by batch class id.
 * 
 * @param batchClassId String
 * @return List<BatchClassEmailConfiguration>
 */
@Override
public List<BatchClassEmailConfiguration> getEmailConfigByBatchClassIdentifier(final String batchClassIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(BATCH_CLASS_IDENTIFIER, batchClassIdentifier));
    return find(criteria);
}
项目:ephesoft    文件:BatchClassEmailConfigDaoImpl.java   
/**
 * An api to fetch all DocumentType by batch class id starting at firstIndex and maxResults is the total number of records.
 * 
 * @param batchClassIdentifier String
 * @param firstIndex int
 * @param maxResults int
 * @return List<BatchClassEmailConfiguration>
 */
@Override
public List<BatchClassEmailConfiguration> getEmailConfigByBatchClassIdentifier(final String batchClassIdentifier, final int firstIndex,
        final int maxResults) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(BATCH_CLASS_IDENTIFIER, batchClassIdentifier));
    return find(criteria, firstIndex, maxResults);
}
项目:ephesoft    文件:BatchClassScannerDaoImpl.java   
/**
 * API to get the profiles for a batch class.
 * 
 * @param batchClassId String
 * @return List<BatchClassScannerConfiguration>
 */
@Override
public List<BatchClassScannerConfiguration> getProfilesByBatchClass(String batchClassId) {
    LOG.info("Batch Class id:" + batchClassId);
    DetachedCriteria criteria = criteria();
    criteria.createAlias("batchClass", "batchClass", JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq("batchClass.identifier", batchClassId));
    criteria.add(Restrictions.isNull("parent"));
    return find(criteria);
}
项目:ephesoft    文件:TableInfoDaoImpl.java   
/**
 * An API to fetch all TableInfo by document type name.
 * 
 * @param docTypeName String
 * @param batchClassIdentifier String
 * @return List<TableInfo>
 */
@Override
public List<TableInfo> getTableInfoByDocTypeName(String docTypeName, String batchClassIdentifier) {

    LOGGER.info("Document type name : " + docTypeName);
    DetachedCriteria criteria = criteria();
    criteria.createAlias("docType", "docType", JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq("docType.name", docTypeName));
    criteria.createAlias("docType.batchClass", "batchClass", JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq("batchClass.identifier", batchClassIdentifier));

    return find(criteria);

}