Java Code Examples for org.hibernate.internal.util.collections.ArrayHelper

The following examples show how to use org.hibernate.internal.util.collections.ArrayHelper. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException {
	// first, figure out how many batchable ids we have...
	final Serializable[] batch = session.getPersistenceContextInternal()
			.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( (SessionImplementor) session, idsToLoad, collectionPersister().getKeyType() );
}
 
Example 2
@Override
public CompletionStage<Void> reactiveInitialize(Serializable id, SharedSessionContractImplementor session) {
	final Serializable[] batch = session.getPersistenceContextInternal()
			.getBatchFetchQueue()
			.getCollectionBatch( collectionPersister(), id, maxBatchSize );
	final int numberOfIds = ArrayHelper.countNonNull( batch );
	if ( numberOfIds <= 1 ) {
		return singleKeyLoader.reactiveLoadCollection( (SessionImplementor) session, id,
				collectionPersister().getKeyType() );
	}

	final Serializable[] idsToLoad = new Serializable[numberOfIds];
	System.arraycopy( batch, 0, idsToLoad, 0, numberOfIds );

	return batchLoader.doBatchedCollectionLoad( (SessionImplementor) session, idsToLoad,
			collectionPersister().getKeyType() );
}
 
Example 3
protected LegacyBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockMode lockMode,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new EntityLoader[ batchSizes.length ];
	final EntityLoader.Builder entityLoaderBuilder = EntityLoader.forEntity( persister )
			.withInfluencers( loadQueryInfluencers )
			.withLockMode( lockMode )
			.withLockOptions( lockOptions );

	// we create a first entity loader to use it as a template for the others
	this.loaders[0] = entityLoaderBuilder.withBatchSize( batchSizes[0] ).byPrimaryKey();

	for ( int i = 1; i < batchSizes.length; i++ ) {
		this.loaders[i] = entityLoaderBuilder.withEntityLoaderTemplate( this.loaders[0] ).withBatchSize( batchSizes[i] ).byPrimaryKey();
	}
}
 
Example 4
Source Project: lams   Source File: CriteriaLoader.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Object[] getResultRow(Object[] row, ResultSet rs, SharedSessionContractImplementor session)
		throws SQLException, HibernateException {
	final Object[] result;
	if ( translator.hasProjection() ) {
		Type[] types = translator.getProjectedTypes();
		result = new Object[types.length];
		String[] columnAliases = translator.getProjectedColumnAliases();
		for ( int i=0, pos=0; i<result.length; i++ ) {
			int numColumns = types[i].getColumnSpan( session.getFactory() );
			if ( numColumns > 1 ) {
				String[] typeColumnAliases = ArrayHelper.slice( columnAliases, pos, numColumns );
				result[i] = types[i].nullSafeGet(rs, typeColumnAliases, session, null);
			}
			else {
				result[i] = types[i].nullSafeGet(rs, columnAliases[pos], session, null);
			}
			pos += numColumns;
		}
	}
	else {
		result = toResultRow( row );
	}
	return result;
}
 
Example 5
Source Project: lams   Source File: CustomLoader.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void autoDiscoverTypes(ResultSet rs) {
	try {
		JdbcResultMetadata metadata = new JdbcResultMetadata( getFactory(), rs );
		rowProcessor.prepareForAutoDiscovery( metadata );

		List<String> aliases = new ArrayList<>();
		List<Type> types = new ArrayList<>();
		for ( ResultColumnProcessor resultProcessor : rowProcessor.getColumnProcessors() ) {
			resultProcessor.performDiscovery( metadata, types, aliases );
		}

		validateAliases( aliases );

		resultTypes = ArrayHelper.toTypeArray( types );
		transformerAliases = ArrayHelper.toStringArray( aliases );
	}
	catch (SQLException e) {
		throw new HibernateException( "Exception while trying to autodiscover types.", e );
	}
}
 
Example 6
@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() );
}
 
Example 7
Source Project: lams   Source File: OneToManyPersister.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate the SQL UPDATE that updates a particular row's foreign
 * key to null
 */
@Override
protected String generateDeleteRowString() {
	final Update update = new Update( getDialect() )
			.setTableName( qualifiedTableName )
			.addColumns( keyColumnNames, "null" );

	if ( hasIndex && !indexContainsFormula ) {
		for ( int i = 0 ; i < indexColumnNames.length ; i++ ) {
			if ( indexColumnIsSettable[i] ) {
				update.addColumn( indexColumnNames[i], "null" );
			}
		}
	}

	if ( getFactory().getSessionFactoryOptions().isCommentsEnabled() ) {
		update.setComment( "delete one-to-many row " + getRole() );
	}

	//use a combination of foreign key columns and pk columns, since
	//the ordering of removal and addition is not guaranteed when
	//a child moves from one parent to another
	String[] rowSelectColumnNames = ArrayHelper.join( keyColumnNames, elementColumnNames );
	return update.addPrimaryKeyColumns( rowSelectColumnNames )
			.toStatementString();
}
 
Example 8
public NativeSQLQuerySpecification(
		String queryString,
		NativeSQLQueryReturn[] queryReturns,
		Collection querySpaces) {
	this.queryString = queryString;
	this.queryReturns = queryReturns;
	if ( querySpaces == null ) {
		this.querySpaces = Collections.EMPTY_SET;
	}
	else {
		Set tmp = new HashSet();
		tmp.addAll( querySpaces );
		this.querySpaces = Collections.unmodifiableSet( tmp );
	}

	// pre-determine and cache the hashcode
	int hashCode = queryString.hashCode();
	hashCode = 29 * hashCode + this.querySpaces.hashCode();
	if ( this.queryReturns != null ) {
		hashCode = 29 * hashCode + ArrayHelper.toList( this.queryReturns ).hashCode();
	}
	this.hashCode = hashCode;
}
 
Example 9
Source Project: lams   Source File: JoinHelper.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the qualified (prefixed by alias) names of the columns of the owning entity which are to be used in the join
 *
 * @param associationType The association type for the association that represents the join
 * @param columnQualifier The left-hand side table alias
 * @param propertyIndex The index of the property that represents the association/join
 * @param begin The index for any nested (composites) attributes
 * @param lhsPersister The persister for the left-hand side of the association/join
 * @param mapping The mapping (typically the SessionFactory).
 *
 * @return The qualified column names.
 */
public static String[] getAliasedLHSColumnNames(
		AssociationType associationType,
		String columnQualifier,
		int propertyIndex,
		int begin,
		OuterJoinLoadable lhsPersister,
		Mapping mapping) {
	if ( associationType.useLHSPrimaryKey() ) {
		return StringHelper.qualify( columnQualifier, lhsPersister.getIdentifierColumnNames() );
	}
	else {
		final String propertyName = associationType.getLHSPropertyName();
		if ( propertyName == null ) {
			return ArrayHelper.slice(
					toColumns( lhsPersister, columnQualifier, propertyIndex ),
					begin,
					associationType.getColumnSpan( mapping )
			);
		}
		else {
			//bad cast
			return ( (PropertyMapping) lhsPersister ).toColumns( columnQualifier, propertyName );
		}
	}
}
 
Example 10
@Override
public CompletionStage<Object> load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions, Boolean readOnly) {
	final Serializable[] batch = session.getPersistenceContextInternal()
			.getBatchFetchQueue()
			.getEntityBatch( persister(), id, batchSizes[0], persister().getEntityMode() );

	final int numberOfIds = ArrayHelper.countNonNull( batch );
	if ( numberOfIds <= 1 ) {
		return loaders[batchSizes.length-1]
				.load( id, optionalObject, session )
				.thenApply( optional -> {
					if ( optional == null ) {
						// There was no entity with the specified ID. Make sure the EntityKey does not remain
						// in the batch to avoid including it in future batches that get executed.
						BatchFetchQueueHelper.removeBatchLoadableEntityKey( id, persister(), session );
					}
					return optional;
				});
	}

	// 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;
	}

	return doBatchLoad( id, loaders[indexToUse], session, idsToLoad, optionalObject, lockOptions, readOnly );
}
 
Example 11
@Override
	public ReactiveCollectionLoader createRealBatchingCollectionInitializer(
			QueryableCollection persister,
			int maxBatchSize,
			SessionFactoryImplementor factory,
			LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
		int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
		ReactiveCollectionLoader[] loaders = new ReactiveCollectionLoader[ batchSizes.length ];
		for ( int i = 0; i < batchSizes.length; i++ ) {
			throw new UnsupportedOperationException();
//			loaders[i] = new ReactiveBasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
		}
		return new ReactivePaddedBatchingCollectionInitializer( persister, batchSizes, loaders, factory, loadQueryInfluencers);
	}
 
Example 12
@Override
public ReactiveCollectionLoader createRealBatchingOneToManyInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	final ReactiveCollectionLoader[] loaders = new ReactiveCollectionLoader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new ReactiveOneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new ReactivePaddedBatchingCollectionInitializer( persister, batchSizes, loaders, factory, loadQueryInfluencers);
}
 
Example 13
@Override
public CompletionStage<Void> reactiveInitialize(Serializable id, SharedSessionContractImplementor session) {
	final Serializable[] batch = session.getPersistenceContextInternal()
			.getBatchFetchQueue()
			.getCollectionBatch( persister, id, batchSizes[0] );
	final int numberOfIds = ArrayHelper.countNonNull( batch );
	if ( numberOfIds <= 1 ) {
		loaders[batchSizes.length-1].loadCollection( session, id, persister.getKeyType() );
		return CompletionStages.nullFuture();
	}

	// 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;
	}

	return loaders[indexToUse].reactiveLoadCollectionBatch(
			(SessionImplementor) session,
			idsToLoad,
			persister.getKeyType()
	);
}
 
Example 14
@Override
public boolean[] toColumnNullness(Object value, Mapping mapping) {
    if (value instanceof Map && ((Map) value).isEmpty()) {
        return ArrayHelper.FALSE;
    }
    return super.toColumnNullness(value, mapping);
}
 
Example 15
Source Project: lams   Source File: ComponentType.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object hydrate(
		final ResultSet rs,
		final String[] names,
		final SharedSessionContractImplementor session,
		final Object owner)
		throws HibernateException, SQLException {

	int begin = 0;
	boolean notNull = false;
	Object[] values = new Object[propertySpan];
	for ( int i = 0; i < propertySpan; i++ ) {
		int length = propertyTypes[i].getColumnSpan( session.getFactory() );
		String[] range = ArrayHelper.slice( names, begin, length ); //cache this
		Object val = propertyTypes[i].hydrate( rs, range, session, owner );
		if ( val == null ) {
			if ( isKey ) {
				return null; //different nullability rules for pk/fk
			}
		}
		else {
			notNull = true;
		}
		values[i] = val;
		begin += length;
	}

	return notNull ? values : null;
}
 
Example 16
Source Project: lams   Source File: ConfigurationHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convert a string to an array of strings.  The assumption is that
 * the individual array elements are delimited in the source stringForm
 * param by the delim param.
 *
 * @param stringForm The string form of the string array.
 * @param delim The delimiter used to separate individual array elements.
 * @return The array; never null, though may be empty.
 */
public static String[] toStringArray(String stringForm, String delim) {
	// todo : move to StringHelper?
	if ( stringForm != null ) {
		return StringHelper.split( delim, stringForm );
	}
	else {
		return ArrayHelper.EMPTY_STRING_ARRAY;
	}
}
 
Example 17
public LegacyBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockMode, factory, loadQueryInfluencers);
	}
}
 
Example 18
public LegacyBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockOptions, factory, loadQueryInfluencers);
	}
}
 
Example 19
public PaddedBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockMode, factory, loadQueryInfluencers);
	}
	validate( maxBatchSize );
}
 
Example 20
public PaddedBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		this.loaders[i] = new EntityLoader( persister, batchSizes[i], lockOptions, factory, loadQueryInfluencers);
	}
	validate( maxBatchSize );
}
 
Example 21
@Override
public Object load(Serializable id, Object optionalObject, SharedSessionContractImplementor session, LockOptions lockOptions) {
	final Serializable[] batch = session.getPersistenceContext()
			.getBatchFetchQueue()
			.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 );
		if ( result == null ) {
			// There was no entity with the specified ID. Make sure the EntityKey does not remain
			// in the batch to avoid including it in future batches that get executed.
			BatchFetchQueueHelper.removeBatchLoadableEntityKey( id, persister(), session );
		}
		return result;
	}

	// 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;
	}

	return doBatchLoad( id, loaders[indexToUse], session, idsToLoad, optionalObject, lockOptions );
}
 
Example 22
Source Project: lams   Source File: CriteriaJoinWalker.java    License: GNU General Public License v2.0 5 votes vote down vote up
public CriteriaJoinWalker(
		final OuterJoinLoadable persister,
		final CriteriaQueryTranslator translator,
		final SessionFactoryImplementor factory,
		final CriteriaImpl criteria,
		final String rootEntityName,
		final LoadQueryInfluencers loadQueryInfluencers,
		final String alias) {
	super( persister, factory, loadQueryInfluencers, alias );

	this.translator = translator;

	querySpaces = translator.getQuerySpaces();

	if ( translator.hasProjection() ) {
		initProjection(
				translator.getSelect(),
				translator.getWhereCondition(),
				translator.getOrderBy(),
				translator.getGroupBy(),
				LockOptions.NONE
		);
		resultTypes = translator.getProjectedTypes();
		userAliases = translator.getProjectedAliases();
		includeInResultRow = new boolean[resultTypes.length];
		Arrays.fill( includeInResultRow, true );
	}
	else {
		initAll( translator.getWhereCondition(), translator.getOrderBy(), LockOptions.NONE );
		// root entity comes last
		userAliasList.add( criteria.getAlias() ); //root entity comes *last*
		resultTypeList.add( translator.getResultType( criteria ) );
		includeInResultRowList.add( true );
		userAliases = ArrayHelper.toStringArray( userAliasList );
		resultTypes = ArrayHelper.toTypeArray( resultTypeList );
		includeInResultRow = ArrayHelper.toBooleanArray( includeInResultRowList );
	}
}
 
Example 23
@Override
protected CollectionInitializer createRealBatchingCollectionInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	Loader[] loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new BasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders );
}
 
Example 24
@Override
protected CollectionInitializer createRealBatchingOneToManyInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	final Loader[] loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new OneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders );
}
 
Example 25
@Override
public CollectionInitializer createRealBatchingCollectionInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	Loader[] loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new BasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new PaddedBatchingCollectionInitializer( persister, batchSizes, loaders );
}
 
Example 26
@Override
public CollectionInitializer createRealBatchingOneToManyInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	final Loader[] loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new OneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new PaddedBatchingCollectionInitializer( persister, batchSizes, loaders );
}
 
Example 27
@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() );
}
 
Example 28
@Override
public CollectionInitializer createRealBatchingCollectionInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	Loader[] loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new BasicCollectionLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders );
}
 
Example 29
@Override
public CollectionInitializer createRealBatchingOneToManyInitializer(
		QueryableCollection persister,
		int maxBatchSize,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	final int[] batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	final Loader[] loaders = new Loader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		loaders[i] = new OneToManyLoader( persister, batchSizes[i], factory, loadQueryInfluencers );
	}
	return new LegacyBatchingCollectionInitializer( persister, batchSizes, loaders );
}
 
Example 30
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();
}