public static Serializable[] extractNonNull(Serializable[] array) { final int nonNullCount = countNonNull( array ); final Serializable[] result = new Serializable[nonNullCount]; int i = 0; for ( Serializable element : array ) { if ( element != null ) { result[i++] = element; } } if ( i != nonNullCount ) { throw new HibernateException( "Number of non-null elements varied between iterations" ); } return result; }
@Override public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException { // first, figure out how many batchable ids we have... final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getCollectionBatch( collectionPersister(), id, maxBatchSize ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { singleKeyLoader.loadCollection( session, id, collectionPersister().getKeyType() ); return; } final Serializable[] idsToLoad = new Serializable[numberOfIds]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); batchLoader.doBatchedCollectionLoad( session, idsToLoad, collectionPersister().getKeyType() ); } }
@Override public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException { final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getCollectionBatch( collectionPersister(), id, batchSizes[0] ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { loaders[batchSizes.length-1].loadCollection( session, id, collectionPersister().getKeyType() ); return; } // Uses the first batch-size bigger than the number of actual ids in the batch int indexToUse = batchSizes.length-1; for ( int i = 0; i < batchSizes.length-1; i++ ) { if ( batchSizes[i] >= numberOfIds ) { indexToUse = i; } else { break; } } final Serializable[] idsToLoad = new Serializable[ batchSizes[indexToUse] ]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); for ( int i = numberOfIds; i < batchSizes[indexToUse]; i++ ) { idsToLoad[i] = id; } loaders[indexToUse].loadCollectionBatch( session, idsToLoad, collectionPersister().getKeyType() ); } }
.getEntityBatch( persister(), id, batchSizes[0], persister().getEntityMode() ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { final Object result = ( (UniqueEntityLoader) loaders[batchSizes.length-1] ).load( id, optionalObject, session );
protected AbstractCollectionReference( ExpandingCollectionQuerySpace collectionQuerySpace, PropertyPath propertyPath, boolean shouldIncludeJoins) { this.collectionQuerySpace = collectionQuerySpace; this.propertyPath = propertyPath; this.allowElementJoin = shouldIncludeJoins; // Currently we can only allow a join for the collection index if all of the following are true: // - collection element joins are allowed; // - index is an EntityType; // - index values are not "formulas" (e.g., a @MapKey index is translated into "formula" value(s)). // Hibernate cannot currently support eager joining of associations within a component (@Embeddable) as an index. if ( shouldIncludeJoins && collectionQuerySpace.getCollectionPersister().hasIndex() && collectionQuerySpace.getCollectionPersister().getIndexType().isEntityType() ) { final String[] indexFormulas = ( (QueryableCollection) collectionQuerySpace.getCollectionPersister() ).getIndexFormulas(); final int nNonNullFormulas = ArrayHelper.countNonNull( indexFormulas ); this.allowIndexJoin = nNonNullFormulas == 0; } else { this.allowIndexJoin = false; } // All other fields must be initialized before building this.index and this.element. this.index = buildIndexGraph(); this.element = buildElementGraph(); }
.getEntityBatch( persister(), id, maxBatchSize, persister().getEntityMode() ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { final Object result = singleKeyLoader.load( id, optionalObject, session );
public static Serializable[] extractNonNull(Serializable[] array) { final int nonNullCount = countNonNull( array ); final Serializable[] result = new Serializable[nonNullCount]; int i = 0; for ( Serializable element : array ) { if ( element != null ) { result[i++] = element; } } if ( i != nonNullCount ) { throw new HibernateException( "Number of non-null elements varied between iterations" ); } return result; }
@Override public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions) { final Serializable[] batch = session.getPersistenceContext() .getBatchFetchQueue() .getEntityBatch( persister(), id, maxBatchSize, persister().getEntityMode() ); final int numberOfIds = ArrayHelper.countNonNull( batch ); if ( numberOfIds <= 1 ) { return singleKeyLoader.load( id, optionalObject, session ); } final Serializable[] idsToLoad = new Serializable[numberOfIds]; System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds ); return doBatchLoad( id, dynamicLoader, session, idsToLoad, optionalObject, lockOptions ); }