Java 类org.hibernate.persister.collection.QueryableCollection 实例源码

项目:lams    文件:AbstractEmptinessExpression.java   
@Override
public final String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final String entityName = criteriaQuery.getEntityName( criteria, propertyName );
    final String actualPropertyName = criteriaQuery.getPropertyName( propertyName );
    final String sqlAlias = criteriaQuery.getSQLAlias( criteria, propertyName );

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

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

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

    return excludeEmpty()
            ? "exists " + innerSelect
            : "not exists " + innerSelect;
}
项目:lams    文件:AbstractEmptinessExpression.java   
protected QueryableCollection getQueryableCollection(
        String entityName,
        String propertyName,
        SessionFactoryImplementor factory) throws HibernateException {
    final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
    final Type type = ownerMapping.toType( propertyName );
    if ( !type.isCollectionType() ) {
        throw new MappingException(
                "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
        );
    }

    final String role = ( (CollectionType) type ).getRole();
    try {
        return (QueryableCollection) factory.getCollectionPersister( role );
    }
    catch ( ClassCastException cce ) {
        throw new QueryException( "collection role is not queryable: " + role );
    }
    catch ( Exception e ) {
        throw new QueryException( "collection role not found: " + role );
    }
}
项目:lams    文件:SizeExpression.java   
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    final String entityName =criteriaQuery.getEntityName( criteria, propertyName );
    final String role = entityName + '.' + criteriaQuery.getPropertyName( propertyName );
    final QueryableCollection cp = (QueryableCollection) criteriaQuery.getFactory().getCollectionPersister( role );

    final String[] fk = cp.getKeyColumnNames();
    final String[] pk = ( (Loadable) cp.getOwnerEntityPersister() ).getIdentifierColumnNames();

    final ConditionFragment subQueryRestriction = new ConditionFragment()
            .setTableAlias( criteriaQuery.getSQLAlias( criteria, propertyName ) )
            .setCondition( pk, fk );

    return String.format(
            "? %s (select count(*) from %s where %s)",
            op,
            cp.getTableName(),
            subQueryRestriction.toFragmentString()
    );
}
项目: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    文件:BasicCollectionJoinWalker.java   
public BasicCollectionJoinWalker(
        QueryableCollection collectionPersister, 
        int batchSize, 
        String subquery, 
        SessionFactoryImplementor factory, 
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {

    super( factory, loadQueryInfluencers );

    this.collectionPersister = collectionPersister;

    String alias = generateRootAlias( collectionPersister.getRole() );

    walkCollectionTree(collectionPersister, alias);

    List allAssociations = new ArrayList();
    allAssociations.addAll(associations);
    allAssociations.add( OuterJoinableAssociation.createRoot( collectionPersister.getCollectionType(), alias, getFactory() ) );
    initPersisters(allAssociations, LockMode.NONE);
    initStatementString(alias, batchSize, subquery);
}
项目:lams    文件:SubselectOneToManyLoader.java   
public SubselectOneToManyLoader(
        QueryableCollection persister, 
        String subquery,
        Collection entityKeys,
        QueryParameters queryParameters,
        Map<String, int[]> namedParameterLocMap,
        SessionFactoryImplementor factory, 
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
    super( persister, 1, subquery, factory, loadQueryInfluencers );

    keys = new Serializable[ entityKeys.size() ];
    Iterator iter = entityKeys.iterator();
    int i=0;
    while ( iter.hasNext() ) {
        keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
    }

    this.namedParameters = queryParameters.getNamedParameters();
    this.types = queryParameters.getFilteredPositionalParameterTypes();
    this.values = queryParameters.getFilteredPositionalParameterValues();
    this.namedParameterLocMap = namedParameterLocMap;
}
项目:lams    文件:OneToManyLoader.java   
public OneToManyLoader(
        QueryableCollection oneToManyPersister,
        int batchSize,
        String subquery,
        SessionFactoryImplementor factory,
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
    super( oneToManyPersister, factory, loadQueryInfluencers );

    JoinWalker walker = new OneToManyJoinWalker(
            oneToManyPersister,
            batchSize,
            subquery,
            factory,
            loadQueryInfluencers
    );
    initFromWalker( walker );

    postInstantiate();
    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Static select for one-to-many %s: %s", oneToManyPersister.getRole(), getSQLString() );
    }
}
项目:lams    文件:DynamicBatchingCollectionInitializerBuilder.java   
public DynamicBatchingCollectionInitializer(
        QueryableCollection collectionPersister,
        int maxBatchSize,
        SessionFactoryImplementor factory,
        LoadQueryInfluencers influencers) {
    super( collectionPersister );
    this.maxBatchSize = maxBatchSize;

    if ( collectionPersister.isOneToMany() ) {
        this.singleKeyLoader = new OneToManyLoader( collectionPersister, 1, factory, influencers );
    }
    else {
        this.singleKeyLoader = new BasicCollectionLoader( collectionPersister, 1, factory, influencers );
    }

    this.batchLoader = new DynamicBatchingCollectionLoader( collectionPersister, factory, influencers );
}
项目:lams    文件:DynamicBatchingCollectionInitializerBuilder.java   
public DynamicBatchingCollectionLoader(
        QueryableCollection collectionPersister,
        SessionFactoryImplementor factory,
        LoadQueryInfluencers influencers) {
    super( collectionPersister, factory, influencers );

    JoinWalker walker = buildJoinWalker( collectionPersister, factory, influencers );
    initFromWalker( walker );
    this.sqlTemplate = walker.getSQLString();
    this.alias = StringHelper.generateAlias( collectionPersister.getRole(), 0 );
    postInstantiate();

    if ( LOG.isDebugEnabled() ) {
        LOG.debugf(
                "SQL-template for dynamic collection [%s] batch-fetching : %s",
                collectionPersister.getRole(),
                sqlTemplate
        );
    }
}
项目:lams    文件:SubselectCollectionLoader.java   
public SubselectCollectionLoader(
        QueryableCollection persister, 
        String subquery,
        Collection entityKeys,
        QueryParameters queryParameters,
        Map<String, int[]> namedParameterLocMap,
        SessionFactoryImplementor factory, 
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
    super( persister, 1, subquery, factory, loadQueryInfluencers );

    keys = new Serializable[ entityKeys.size() ];
    Iterator iter = entityKeys.iterator();
    int i=0;
    while ( iter.hasNext() ) {
        keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
    }

    this.namedParameters = queryParameters.getNamedParameters();
    this.types = queryParameters.getFilteredPositionalParameterTypes();
    this.values = queryParameters.getFilteredPositionalParameterValues();
    this.namedParameterLocMap = namedParameterLocMap;

}
项目:lams    文件:OneToManyJoinWalker.java   
public OneToManyJoinWalker(
        QueryableCollection oneToManyPersister,
        int batchSize,
        String subquery,
        SessionFactoryImplementor factory,
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
    super( factory, loadQueryInfluencers );

    this.oneToManyPersister = oneToManyPersister;

    final OuterJoinLoadable elementPersister = (OuterJoinLoadable) oneToManyPersister.getElementPersister();
    final String alias = generateRootAlias( oneToManyPersister.getRole() );

    walkEntityTree(elementPersister, alias);

    List allAssociations = new ArrayList();
    allAssociations.addAll(associations);
    allAssociations.add( OuterJoinableAssociation.createRoot( oneToManyPersister.getCollectionType(), alias, getFactory() ) );
    initPersisters(allAssociations, LockMode.NONE);
    initStatementString(elementPersister, alias, batchSize, subquery);
}
项目:lams    文件:AbstractLoadPlanBasedCollectionInitializer.java   
public AbstractLoadPlanBasedCollectionInitializer(
        QueryableCollection collectionPersister,
        QueryBuildingParameters buildingParameters) {
    super( collectionPersister.getFactory() );
    this.collectionPersister = collectionPersister;

    final FetchStyleLoadPlanBuildingAssociationVisitationStrategy strategy =
            new FetchStyleLoadPlanBuildingAssociationVisitationStrategy(
                    collectionPersister.getFactory(),
                    buildingParameters.getQueryInfluencers(),
                    buildingParameters.getLockMode() != null
                            ? buildingParameters.getLockMode()
                            : buildingParameters.getLockOptions().getLockMode()
    );

    final LoadPlan plan = MetamodelDrivenLoadPlanBuilder.buildRootCollectionLoadPlan( strategy, collectionPersister );
    this.staticLoadQuery = BatchingLoadQueryDetailsFactory.makeCollectionLoadQueryDetails(
            collectionPersister,
            plan,
            buildingParameters
    );
}
项目:lams    文件:BasicCollectionLoader.java   
protected BasicCollectionLoader(
        QueryableCollection collectionPersister,
        int batchSize,
        String subquery,
        SessionFactoryImplementor factory,
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
    super( collectionPersister, factory, loadQueryInfluencers );

    JoinWalker walker = new BasicCollectionJoinWalker(
            collectionPersister,
            batchSize,
            subquery,
            factory,
            loadQueryInfluencers
    );
    initFromWalker( walker );

    postInstantiate();

    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Static select for collection %s: %s", collectionPersister.getRole(), getSQLString() );
    }
}
项目: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    文件:CollectionQuerySpaceImpl.java   
public String[] toAliasedColumns(String alias, String propertyName) {
    final QueryableCollection queryableCollection = (QueryableCollection) persister;
    if ( propertyName.equals( CollectionPropertyNames.COLLECTION_ELEMENTS ) ) {
        return queryableCollection.getElementColumnNames( alias );
    }
    else if ( propertyName.equals( CollectionPropertyNames.COLLECTION_INDICES ) ) {
        return queryableCollection.getIndexColumnNames( alias );
    }
    else {
        throw new IllegalArgumentException(
                String.format(
                        "Collection propertyName must be either %s or %s; instead it was %s.",
                        CollectionPropertyNames.COLLECTION_ELEMENTS,
                        CollectionPropertyNames.COLLECTION_INDICES,
                        propertyName
                )
        );
    }
}
项目:lams    文件:MetamodelGraphWalker.java   
private void visitCollectionElements(CollectionDefinition collectionDefinition) {
    final CollectionElementDefinition elementDefinition = collectionDefinition.getElementDefinition();
    strategy.startingCollectionElements( elementDefinition );

    final Type collectionElementType = elementDefinition.getType();
    if ( collectionElementType.isAnyType() ) {
        visitAnyDefinition( elementDefinition.toAnyMappingDefinition() );
    }
    else if ( collectionElementType.isComponentType() ) {
        visitCompositeDefinition( elementDefinition.toCompositeElementDefinition() );
    }
    else if ( collectionElementType.isEntityType() ) {
        if ( ! collectionDefinition.getCollectionPersister().isOneToMany() ) {
            final QueryableCollection queryableCollection = (QueryableCollection) collectionDefinition.getCollectionPersister();
            addAssociationKey(
                    new AssociationKey(
                            queryableCollection.getTableName(),
                            queryableCollection.getElementColumnNames()
                    )
            );
        }
        visitEntityDefinition( elementDefinition.toEntityDefinition() );
    }

    strategy.finishingCollectionElements( elementDefinition );
}
项目:lams    文件:IndexNode.java   
@Override
public void prepareForDot(String propertyName) throws SemanticException {
    FromElement fromElement = getFromElement();
    if ( fromElement == null ) {
        throw new IllegalStateException( "No FROM element for index operator!" );
    }

    final QueryableCollection queryableCollection = fromElement.getQueryableCollection();
    if ( queryableCollection != null && !queryableCollection.isOneToMany() ) {
        final FromReferenceNode collectionNode = (FromReferenceNode) getFirstChild();
        final String path = collectionNode.getPath() + "[]." + propertyName;
        LOG.debugf( "Creating join for many-to-many elements for %s", path );
        final FromElementFactory factory = new FromElementFactory( fromElement.getFromClause(), fromElement, path );
        // This will add the new from element to the origin.
        final FromElement elementJoin = factory.createElementJoin( queryableCollection );
        setFromElement( elementJoin );
    }
}
项目:lams    文件:MapEntryNode.java   
@Override
protected String[] resolveColumns(QueryableCollection collectionPersister) {
    List selections = new ArrayList();
    determineKeySelectExpressions( collectionPersister, selections );
    determineValueSelectExpressions( collectionPersister, selections );

    String text = "";
    String[] columns = new String[selections.size()];
    for ( int i = 0; i < selections.size(); i++ ) {
        SelectExpression selectExpression = (SelectExpression) selections.get( i );
        text += ( ", " + selectExpression.getExpression() + " as " + selectExpression.getAlias() );
        columns[i] = selectExpression.getExpression();
    }

    text = text.substring( 2 ); //strip leading ", "
    setText( text );
    setResolved();
    return columns;
}
项目:lams    文件:MapEntryNode.java   
private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) {
    AliasGenerator aliasGenerator = new LocalAliasGenerator( 0 );
    appendSelectExpressions( collectionPersister.getIndexColumnNames(), selections, aliasGenerator );
    Type keyType = collectionPersister.getIndexType();
    if ( keyType.isAssociationType() ) {
        EntityType entityType = (EntityType) keyType;
        Queryable keyEntityPersister = (Queryable) sfi().getEntityPersister(
                entityType.getAssociatedEntityName( sfi() )
        );
        SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment(
                collectionTableAlias(),
                null,
                false
        );
        appendSelectExpressions( fragment, selections, aliasGenerator );
    }
}
项目:lams    文件:MapEntryNode.java   
private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) {
    AliasGenerator aliasGenerator = new LocalAliasGenerator( 1 );
    appendSelectExpressions( collectionPersister.getElementColumnNames(), selections, aliasGenerator );
    Type valueType = collectionPersister.getElementType();
    if ( valueType.isAssociationType() ) {
        EntityType valueEntityType = (EntityType) valueType;
        Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister(
                valueEntityType.getAssociatedEntityName( sfi() )
        );
        SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment(
                elementTableAlias(),
                null,
                false
        );
        appendSelectExpressions( fragment, selections, aliasGenerator );
    }
}
项目:lams    文件:SessionFactoryHelper.java   
/**
 * Locate the collection persister by the collection role, requiring that
 * such a persister exist.
 *
 * @param role The collection role name.
 *
 * @return The defined CollectionPersister for this collection role.
 *
 * @throws QueryException Indicates that the collection persister could not be found.
 */
public QueryableCollection requireQueryableCollection(String role) throws QueryException {
    try {
        QueryableCollection queryableCollection = (QueryableCollection) sfi.getCollectionPersister( role );
        if ( queryableCollection != null ) {
            collectionPropertyMappingByRole.put( role, new CollectionPropertyMapping( queryableCollection ) );
        }
        return queryableCollection;
    }
    catch ( ClassCastException cce ) {
        throw new QueryException( "collection role is not queryable: " + role );
    }
    catch ( Exception e ) {
        throw new QueryException( "collection role not found: " + role );
    }
}
项目:lams    文件:HqlSqlWalker.java   
@Override
protected void validateMapPropertyExpression(AST node) throws SemanticException {
    try {
        FromReferenceNode fromReferenceNode = (FromReferenceNode) node;
        QueryableCollection collectionPersister = fromReferenceNode.getFromElement().getQueryableCollection();
        if ( !Map.class.isAssignableFrom( collectionPersister.getCollectionType().getReturnedClass() ) ) {
            throw new SemanticException( "node did not reference a map" );
        }
    }
    catch (SemanticException se) {
        throw se;
    }
    catch (Throwable t) {
        throw new SemanticException( "node did not reference a map" );
    }
}
项目:lams    文件:CollectionType.java   
@Override
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 );
    }
}
项目:cacheonix-core    文件:AbstractEmptinessExpression.java   
public final String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
    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()
            ? "exists " + innerSelect
            : "not exists " + innerSelect;
}
项目:cacheonix-core    文件:AbstractEmptinessExpression.java   
protected QueryableCollection getQueryableCollection(String entityName, String propertyName, SessionFactoryImplementor factory)
        throws HibernateException {
    PropertyMapping ownerMapping = ( PropertyMapping ) factory.getEntityPersister( entityName );
    Type type = ownerMapping.toType( propertyName );
    if ( !type.isCollectionType() ) {
        throw new MappingException(
                "Property path [" + entityName + "." + propertyName + "] does not reference a collection"
        );
    }

    String role = ( ( CollectionType ) type ).getRole();
    try {
        return ( QueryableCollection ) factory.getCollectionPersister( role );
    }
    catch ( ClassCastException cce ) {
        throw new QueryException( "collection role is not queryable: " + role );
    }
    catch ( Exception e ) {
        throw new QueryException( "collection role not found: " + role );
    }
}
项目:cacheonix-core    文件:SizeExpression.java   
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)
                    .toFragmentString() +
            ")";
}
项目: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    文件:SubselectOneToManyLoader.java   
public SubselectOneToManyLoader(
        QueryableCollection persister, 
        String subquery,
        Collection entityKeys,
        QueryParameters queryParameters,
        Map namedParameterLocMap,
        SessionFactoryImplementor factory, 
        Map enabledFilters)
throws MappingException {

    super(persister, 1, subquery, factory, enabledFilters);

    keys = new Serializable[ entityKeys.size() ];
    Iterator iter = entityKeys.iterator();
    int i=0;
    while ( iter.hasNext() ) {
        keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
    }

    this.namedParameters = queryParameters.getNamedParameters();
    this.types = queryParameters.getFilteredPositionalParameterTypes();
    this.values = queryParameters.getFilteredPositionalParameterValues();
    this.namedParameterLocMap = namedParameterLocMap;

}
项目:cacheonix-core    文件:OneToManyLoader.java   
public OneToManyLoader(
        QueryableCollection oneToManyPersister, 
        int batchSize, 
        String subquery, 
        SessionFactoryImplementor factory, 
        Map enabledFilters)
throws MappingException {

    super(oneToManyPersister, factory, enabledFilters);

    JoinWalker walker = new OneToManyJoinWalker(
            oneToManyPersister, 
            batchSize, 
            subquery, 
            factory, 
            enabledFilters
        );
    initFromWalker( walker );

    postInstantiate();

    log.debug( "Static select for one-to-many " + oneToManyPersister.getRole() + ": " + getSQLString() );
}
项目:cacheonix-core    文件:SubselectCollectionLoader.java   
public SubselectCollectionLoader(
        QueryableCollection persister, 
        String subquery,
        Collection entityKeys,
        QueryParameters queryParameters,
        Map namedParameterLocMap,
        SessionFactoryImplementor factory, 
        Map enabledFilters)
throws MappingException {

    super(persister, 1, subquery, factory, enabledFilters);

    keys = new Serializable[ entityKeys.size() ];
    Iterator iter = entityKeys.iterator();
    int i=0;
    while ( iter.hasNext() ) {
        keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
    }

    this.namedParameters = queryParameters.getNamedParameters();
    this.types = queryParameters.getFilteredPositionalParameterTypes();
    this.values = queryParameters.getFilteredPositionalParameterValues();
    this.namedParameterLocMap = namedParameterLocMap;

}
项目:cacheonix-core    文件:BasicCollectionLoader.java   
protected BasicCollectionLoader(
        QueryableCollection collectionPersister, 
        int batchSize, 
        String subquery, 
        SessionFactoryImplementor factory, 
        Map enabledFilters)
throws MappingException {

    super(collectionPersister, factory, enabledFilters);

    JoinWalker walker = new BasicCollectionJoinWalker(
            collectionPersister, 
            batchSize, 
            subquery, 
            factory, 
            enabledFilters
        );
    initFromWalker( walker );

    postInstantiate();

    log.debug( "Static select for collection " + collectionPersister.getRole() + ": " + getSQLString() );
}
项目:cacheonix-core    文件:BatchingCollectionInitializer.java   
public static CollectionInitializer createBatchingOneToManyInitializer(
    final QueryableCollection persister,
    final int maxBatchSize,
    final SessionFactoryImplementor factory,
    final Map enabledFilters)
throws MappingException {

    if ( maxBatchSize>1 ) {
        int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize);
        Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ];
        for ( int i=0; i<batchSizesToCreate.length; i++ ) {
            loadersToCreate[i] = new OneToManyLoader(persister, batchSizesToCreate[i], factory, enabledFilters);
        }
        return new BatchingCollectionInitializer(persister, batchSizesToCreate, loadersToCreate);
    }
    else {
        return new OneToManyLoader(persister, factory, enabledFilters);
    }
}
项目:cacheonix-core    文件:BatchingCollectionInitializer.java   
public static CollectionInitializer createBatchingCollectionInitializer(
    final QueryableCollection persister,
    final int maxBatchSize,
    final SessionFactoryImplementor factory,
    final Map enabledFilters)
throws MappingException {

    if ( maxBatchSize>1 ) {
        int[] batchSizesToCreate = ArrayHelper.getBatchSizes(maxBatchSize);
        Loader[] loadersToCreate = new Loader[ batchSizesToCreate.length ];
        for ( int i=0; i<batchSizesToCreate.length; i++ ) {
            loadersToCreate[i] = new BasicCollectionLoader(persister, batchSizesToCreate[i], factory, enabledFilters);
        }
        return new BatchingCollectionInitializer(persister, batchSizesToCreate, loadersToCreate);
    }
    else {
        return new BasicCollectionLoader(persister, factory, enabledFilters);
    }
}
项目: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    文件:IndexNode.java   
public void prepareForDot(String propertyName) throws SemanticException {
    FromElement fromElement = getFromElement();
    if ( fromElement == null ) {
        throw new IllegalStateException( "No FROM element for index operator!" );
    }
    QueryableCollection queryableCollection = fromElement.getQueryableCollection();
    if ( queryableCollection != null && !queryableCollection.isOneToMany() ) {

        FromReferenceNode collectionNode = ( FromReferenceNode ) getFirstChild();
        String path = collectionNode.getPath() + "[]." + propertyName;
        if ( log.isDebugEnabled() ) {
            log.debug( "Creating join for many-to-many elements for " + path );
        }
        FromElementFactory factory = new FromElementFactory( fromElement.getFromClause(), fromElement, path );
        // This will add the new from element to the origin.
        FromElement elementJoin = factory.createElementJoin( queryableCollection );
        setFromElement( elementJoin );
    }
}
项目:cacheonix-core    文件:SessionFactoryHelper.java   
/**
 * Locate the collection persister by the collection role, requiring that
 * such a persister exist.
 *
 * @param role The collection role name.
 * @return The defined CollectionPersister for this collection role.
 * @throws QueryException Indicates that the collection persister could not be found.
 */
public QueryableCollection requireQueryableCollection(String role) throws QueryException {
    try {
        QueryableCollection queryableCollection = ( QueryableCollection ) sfi.getCollectionPersister( role );
        if ( queryableCollection != null ) {
            collectionPropertyMappingByRole.put( role, new CollectionPropertyMapping( queryableCollection ) );
        }
        return queryableCollection;
    }
    catch ( ClassCastException cce ) {
        throw new QueryException( "collection role is not queryable: " + role );
    }
    catch ( Exception e ) {
        throw new QueryException( "collection role not found: " + role );
    }
}
项目: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    文件:CollectionType.java   
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 );
    }
}
项目:lams    文件:CollectionElementLoader.java   
public CollectionElementLoader(
        QueryableCollection collectionPersister,
        SessionFactoryImplementor factory,
        LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
    super( factory, loadQueryInfluencers );

    this.keyType = collectionPersister.getKeyType();
    this.indexType = collectionPersister.getIndexType();
    this.persister = (OuterJoinLoadable) collectionPersister.getElementPersister();
    this.entityName = persister.getEntityName();

    JoinWalker walker = new EntityJoinWalker(
            persister, 
            ArrayHelper.join(
                    collectionPersister.getKeyColumnNames(),
                    collectionPersister.toColumns("index")
            ),
            1, 
            LockMode.NONE, 
            factory, 
            loadQueryInfluencers
        );
    initFromWalker( walker );

    postInstantiate();

    if ( LOG.isDebugEnabled() ) {
        LOG.debugf( "Static select for entity %s: %s", entityName, getSQLString() );
    }

}
项目:lams    文件:ComponentCollectionCriteriaInfoProvider.java   
ComponentCollectionCriteriaInfoProvider(QueryableCollection persister) {
    this.persister = persister;
    if ( !persister.getElementType().isComponentType() ) {
        throw new IllegalArgumentException( "persister for role " + persister.getRole() + " is not a collection-of-component" );
    }

    ComponentType componentType = (ComponentType) persister.getElementType();
    String[] names = componentType.getPropertyNames();
    Type[] types = componentType.getSubtypes();

    for ( int i = 0; i < names.length; i++ ) {
        subTypes.put( names[i], types[i] );
    }

}