Java Code Examples for org.hibernate.persister.entity.OuterJoinLoadable

The following examples show how to use org.hibernate.persister.entity.OuterJoinLoadable. 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
private static QueryParameters buildMultiLoadQueryParameters(
		OuterJoinLoadable persister,
		Serializable[] ids,
		LockOptions lockOptions) {
	Type[] types = new Type[ids.length];
	Arrays.fill( types, persister.getIdentifierType() );

	QueryParameters qp = new QueryParameters();
	qp.setOptionalEntityName( persister.getEntityName() );
	qp.setPositionalParameterTypes( types );
	qp.setPositionalParameterValues( ids );
	qp.setLockOptions( lockOptions );
	qp.setOptionalObject( null );
	qp.setOptionalId( null );
	return qp;
}
 
Example 2
Source Project: lams   Source File: EntityLoadQueryDetails.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Applies "table fragments" to the FROM-CLAUSE of the given SelectStatementBuilder for the given Loadable
 *
 * @param select The SELECT statement builder
 *
 * @see org.hibernate.persister.entity.OuterJoinLoadable#fromTableFragment(java.lang.String)
 * @see org.hibernate.persister.entity.Joinable#fromJoinFragment(java.lang.String, boolean, boolean)
 */
protected void applyRootReturnTableFragments(SelectStatementBuilder select) {
	final String fromTableFragment;
	final String rootAlias = entityReferenceAliases.getTableAlias();
	final OuterJoinLoadable outerJoinLoadable = (OuterJoinLoadable) getRootEntityReturn().getEntityPersister();
	final Dialect dialect = getSessionFactory().getJdbcServices().getJdbcEnvironment().getDialect();
	if ( getQueryBuildingParameters().getLockOptions() != null ) {
		fromTableFragment = dialect.appendLockHint(
				getQueryBuildingParameters().getLockOptions(),
				outerJoinLoadable.fromTableFragment( rootAlias )
		);
		select.setLockOptions( getQueryBuildingParameters().getLockOptions() );
	}
	else if ( getQueryBuildingParameters().getLockMode() != null ) {
		fromTableFragment = dialect.appendLockHint(
				getQueryBuildingParameters().getLockMode(),
				outerJoinLoadable.fromTableFragment( rootAlias )
		);
		select.setLockMode( getQueryBuildingParameters().getLockMode() );
	}
	else {
		fromTableFragment = outerJoinLoadable.fromTableFragment( rootAlias );
	}
	select.appendFromClauseFragment( fromTableFragment + outerJoinLoadable.fromJoinFragment( rootAlias, true, true ) );
}
 
Example 3
public CascadeEntityLoader(
		OuterJoinLoadable persister,
		CascadingAction action,
		SessionFactoryImplementor factory) 
throws MappingException {
	super(
			persister, 
			persister.getIdentifierType(), 
			factory, 
			CollectionHelper.EMPTY_MAP
		);

	JoinWalker walker = new CascadeEntityJoinWalker(
			persister, 
			action,
			factory
		);
	initFromWalker( walker );

	postInstantiate();
	
	log.debug( "Static select for action " + action + " on entity " + entityName + ": " + getSQLString() );

}
 
Example 4
Source Project: lams   Source File: JoinWalker.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Determine the appropriate type of join (if any) to use to fetch the
 * given association.
 *
 * @param persister The owner of the association.
 * @param path The path to the association
 * @param propertyNumber The property number representing the association.
 * @param associationType The association type.
 * @param metadataFetchMode The metadata-defined fetch mode.
 * @param metadataCascadeStyle The metadata-defined cascade style.
 * @param lhsTable The owner table
 * @param lhsColumns The owner join columns
 * @param nullable Is the association nullable.
 * @param currentDepth Current join depth
 *
 * @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN},
 * {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
 *
 * @throws MappingException ??
 */
protected JoinType getJoinType(
		OuterJoinLoadable persister,
		final PropertyPath path,
		int propertyNumber,
		AssociationType associationType,
		FetchMode metadataFetchMode,
		CascadeStyle metadataCascadeStyle,
		String lhsTable,
		String[] lhsColumns,
		final boolean nullable,
		final int currentDepth) throws MappingException {
	return getJoinType(
			associationType,
			metadataFetchMode,
			path,
			lhsTable,
			lhsColumns,
			nullable,
			currentDepth,
			metadataCascadeStyle
	);
}
 
Example 5
@Override
protected void applyRootReturnSelectFragments(SelectStatementBuilder selectStatementBuilder) {
	selectStatementBuilder.appendSelectClauseFragment(
		getQueryableCollection().selectFragment(
				getCollectionReferenceAliases().getCollectionTableAlias(),
				getCollectionReferenceAliases().getCollectionColumnAliases().getSuffix()
		)
	);
	if ( getQueryableCollection().isManyToMany() ) {
		final OuterJoinLoadable elementPersister = (OuterJoinLoadable) getQueryableCollection().getElementPersister();
		selectStatementBuilder.appendSelectClauseFragment(
				elementPersister.selectFragment(
						getCollectionReferenceAliases().getElementTableAlias(),
						getCollectionReferenceAliases().getEntityElementAliases().getColumnAliases().getSuffix()
				)
		);
	}
	super.applyRootReturnSelectFragments( selectStatementBuilder );
}
 
Example 6
public static UniqueEntityLoader createBatchingEntityLoader(
	final OuterJoinLoadable persister,
	final int maxBatchSize,
	final LockMode lockMode,
	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 EntityLoader(persister, batchSizesToCreate[i], lockMode, factory, enabledFilters);
		}
		return new BatchingEntityLoader(persister, batchSizesToCreate, loadersToCreate);
	}
	else {
		return new EntityLoader(persister, lockMode, factory, enabledFilters);
	}
}
 
Example 7
public ReactiveCascadeEntityLoader(
		OuterJoinLoadable persister,
		CascadingAction action,
		SessionFactoryImplementor factory) throws MappingException {
	super(
			persister,
			persister.getIdentifierType(),
			factory,
			LoadQueryInfluencers.NONE
	);

	initFromWalker( new CascadeEntityJoinWalker( persister, action, factory ) );

	postInstantiate();

	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Static select for action %s on entity %s: %s", action, entityName, getSQLString() );
	}
}
 
Example 8
public EntityLoader(
		OuterJoinLoadable persister, 
		int batchSize, 
		LockMode lockMode,
		SessionFactoryImplementor factory, 
		Map enabledFilters) 
throws MappingException {
	this( 
			persister, 
			persister.getIdentifierColumnNames(), 
			persister.getIdentifierType(), 
			batchSize,
			lockMode,
			factory, 
			enabledFilters 
		);
}
 
Example 9
Source Project: lams   Source File: EntityJoinWalker.java    License: GNU General Public License v2.0 6 votes vote down vote up
public EntityJoinWalker(
		OuterJoinLoadable persister, 
		String[] uniqueKey, 
		int batchSize, 
		LockMode lockMode,
		final SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( persister, factory, loadQueryInfluencers );

	this.lockOptions.setLockMode(lockMode);
	
	StringBuilder whereCondition = whereString( getAlias(), uniqueKey, batchSize )
			//include the discriminator and class-level where, but not filters
			.append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) );

	AssociationInitCallbackImpl callback = new AssociationInitCallbackImpl( factory );
	initAll( whereCondition.toString(), "", lockOptions, callback );
	this.compositeKeyManyToOneTargetIndices = callback.resolve();
}
 
Example 10
Source Project: lams   Source File: EntityJoinWalker.java    License: GNU General Public License v2.0 6 votes vote down vote up
public EntityJoinWalker(
		OuterJoinLoadable persister,
		String[] uniqueKey,
		int batchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( persister, factory, loadQueryInfluencers );
	LockOptions.copy(lockOptions, this.lockOptions);

	StringBuilder whereCondition = whereString( getAlias(), uniqueKey, batchSize )
			//include the discriminator and class-level where, but not filters
			.append( persister.filterFragment( getAlias(), Collections.EMPTY_MAP ) );

	AssociationInitCallbackImpl callback = new AssociationInitCallbackImpl( factory );
	initAll( whereCondition.toString(), "", lockOptions, callback );
	this.compositeKeyManyToOneTargetIndices = callback.resolve();
}
 
Example 11
Source Project: lams   Source File: EntityLoader.java    License: GNU General Public License v2.0 6 votes vote down vote up
public EntityLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	this(
			persister,
			persister.getIdentifierColumnNames(),
			persister.getIdentifierType(),
			batchSize,
			lockOptions,
			factory,
			loadQueryInfluencers
		);
}
 
Example 12
public String selectFragment(
	        Joinable rhs,
	        String rhsAlias,
	        String lhsAlias,
	        String entitySuffix,
	        String collectionSuffix,
	        boolean includeCollectionColumns) {
		StringBuffer buf = new StringBuffer();
		if ( includeCollectionColumns ) {
//			buf.append( selectFragment( lhsAlias, "" ) )//ignore suffix for collection columns!
			buf.append( selectFragment( lhsAlias, collectionSuffix ) )
					.append( ", " );
		}
		OuterJoinLoadable ojl = ( OuterJoinLoadable ) getElementPersister();
		return buf.append( ojl.selectFragment( lhsAlias, entitySuffix ) )//use suffix for the entity columns
				.toString();
	}
 
Example 13
@Override
public FetchStrategy determineFetchPlan(LoadQueryInfluencers loadQueryInfluencers, PropertyPath propertyPath) {
	final EntityPersister owningPersister = getSource().getEntityPersister();

	FetchStyle style = FetchStrategyHelper.determineFetchStyleByProfile(
			loadQueryInfluencers,
			owningPersister,
			propertyPath,
			attributeNumber()
	);
	if ( style == null ) {
		style = FetchStrategyHelper.determineFetchStyleByMetadata(
				( (OuterJoinLoadable) getSource().getEntityPersister() ).getFetchMode( attributeNumber() ),
				getType(),
				sessionFactory()
		);
	}

	return new FetchStrategy(
			FetchStrategyHelper.determineFetchTiming( style, getType(), sessionFactory() ),
			style
	);
}
 
Example 14
public CompletionStage<List<Object>> multiLoad(
		OuterJoinLoadable persister,
		Serializable[] ids,
		SessionImplementor session,
		MultiLoadOptions loadOptions) {
	return loadOptions.isOrderReturnEnabled() ?
			performOrderedMultiLoad(persister, ids, session, loadOptions) :
			performUnorderedMultiLoad(persister, ids, session, loadOptions);
}
 
Example 15
@Override
protected UniqueEntityLoader buildBatchingLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers influencers) {
	return new ReactiveDynamicBatchingEntityDelegator( persister, batchSize, lockMode, factory, influencers );
}
 
Example 16
public ReactiveEntityLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	this(
			persister,
			persister.getIdentifierType(),
			factory,
			loadQueryInfluencers,
			new EntityJoinWalker(
					persister,
					persister.getIdentifierColumnNames(),
					batchSize,
					lockOptions,
					factory,
					loadQueryInfluencers
			) );

	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Static select for entity %s [%s:%s]: %s",
				entityName,
				lockOptions.getLockMode(),
				lockOptions.getTimeOut(),
				getSQLString() );
	}
}
 
Example 17
private ReactiveEntityLoader(
		OuterJoinLoadable persister,
		Type uniqueKeyType,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers,
		EntityJoinWalker walker) throws MappingException {
	super( persister, uniqueKeyType, factory, loadQueryInfluencers );

	initFromWalker( walker );
	compositeKeyManyToOneTargetIndices = walker.getCompositeKeyManyToOneTargetIndices();
	postInstantiate();
}
 
Example 18
@Override
protected UniqueEntityLoader buildBatchingLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers influencers) {
	return new ReactivePaddedBatchingEntityLoader( persister, batchSize, lockMode, factory, influencers );
}
 
Example 19
public static Iterable<AttributeDefinition> getCompositeCollectionIndexSubAttributes(CompositeCollectionElementDefinition compositionElementDefinition){
	final QueryableCollection collectionPersister =
			(QueryableCollection) compositionElementDefinition.getCollectionDefinition().getCollectionPersister();
	return getSingularSubAttributes(
			compositionElementDefinition.getSource(),
			(OuterJoinLoadable) collectionPersister.getOwnerEntityPersister(),
			(CompositeType) collectionPersister.getIndexType(),
			collectionPersister.getTableName(),
			collectionPersister.toColumns( "index" )
	);
}
 
Example 20
public ReactiveDynamicBatchingEntityDelegator(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.maxBatchSize = maxBatchSize;
	this.singleKeyLoader = new ReactiveEntityLoader( persister, 1, lockMode, factory, loadQueryInfluencers );
	this.dynamicLoader = new ReactiveDynamicBatchingEntityLoader( persister, maxBatchSize, lockMode, factory, loadQueryInfluencers );
}
 
Example 21
public ReactiveDynamicBatchingEntityDelegator(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.maxBatchSize = maxBatchSize;
	this.singleKeyLoader = new ReactiveEntityLoader( persister, 1, lockOptions, factory, loadQueryInfluencers );
	this.dynamicLoader = new ReactiveDynamicBatchingEntityLoader( persister, maxBatchSize, lockOptions, factory, loadQueryInfluencers );
}
 
Example 22
@Override
protected void applyRootReturnTableFragments(SelectStatementBuilder selectStatementBuilder) {
	final OuterJoinLoadable elementOuterJoinLoadable =
			(OuterJoinLoadable) getElementEntityReference().getEntityPersister();
	//final String tableAlias = getCollectionReferenceAliases().getCollectionTableAlias();
	final String tableAlias = getElementEntityReferenceAliases().getTableAlias();
	final String fragment =
			elementOuterJoinLoadable.fromTableFragment( tableAlias ) +
					elementOuterJoinLoadable.fromJoinFragment( tableAlias, true, true);
	selectStatementBuilder.appendFromClauseFragment( fragment );
}
 
Example 23
protected UniqueEntityLoader buildNonBatchingLoader(
			OuterJoinLoadable persister,
			LockMode lockMode,
			SessionFactoryImplementor factory,
			LoadQueryInfluencers influencers) {
		return new ReactivePlanEntityLoader.Builder( persister )
				.withLockMode( lockMode )
				.withInfluencers( influencers )
				.byPrimaryKey();
//		return new ReactiveEntityLoader( persister, factory, lockMode, influencers);
	}
 
Example 24
protected UniqueEntityLoader buildNonBatchingLoader(
			OuterJoinLoadable persister,
			LockOptions lockOptions,
			SessionFactoryImplementor factory,
			LoadQueryInfluencers influencers) {
		return new ReactivePlanEntityLoader.Builder( persister )
				.withLockMode( lockOptions.getLockMode() )
				.withInfluencers( influencers )
				.byPrimaryKey();
//		return new ReactiveEntityLoader( persister, factory, lockOptions.getLockMode(), influencers);
	}
 
Example 25
protected UniqueEntityLoader buildBatchingLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers influencers) {
	return new ReactiveEntityLoader( persister, factory, lockMode, influencers);
}
 
Example 26
protected UniqueEntityLoader buildBatchingLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers influencers) {
	return new ReactiveEntityLoader( persister, factory, lockOptions.getLockMode(), influencers);
}
 
Example 27
public CollectionElementLoader(
		QueryableCollection collectionPersister,
		SessionFactoryImplementor factory, 
		Map enabledFilters) 
throws MappingException {
	super(factory, enabledFilters);

	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.getIndexColumnNames()
				),
			1, 
			LockMode.NONE, 
			factory, 
			enabledFilters
		);
	initFromWalker( walker );

	postInstantiate();
	
	log.debug( "Static select for entity " + entityName + ": " + getSQLString() );

}
 
Example 28
/**
 * Get the columns of the owning entity which are to 
 * be used in the join
 */
public static String[] getLHSColumnNames(
		AssociationType type, 
		int property, 
		int begin, 
		OuterJoinLoadable lhsPersister,
		Mapping mapping
) {
	if ( type.useLHSPrimaryKey() ) {
		//return lhsPersister.getSubclassPropertyColumnNames(property);
		return lhsPersister.getIdentifierColumnNames();
	}
	else {
		String propertyName = type.getLHSPropertyName();
		if (propertyName==null) {
			//slice, to get the columns for this component
			//property
			return ArrayHelper.slice( 
					lhsPersister.getSubclassPropertyColumnNames(property),
					begin, 
					type.getColumnSpan(mapping) 
				);
		}
		else {
			//property-refs for associations defined on a
			//component are not supported, so no need to slice
			return lhsPersister.getPropertyColumnNames(propertyName);
		}
	}
}
 
Example 29
public ReactivePaddedBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new ReactiveEntityLoader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		this.loaders[i] = new ReactiveEntityLoader( persister, batchSizes[i], lockMode, factory, loadQueryInfluencers);
	}
	validate( maxBatchSize );
}
 
Example 30
public ReactivePaddedBatchingEntityLoader(
		OuterJoinLoadable persister,
		int maxBatchSize,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) {
	super( persister );
	this.batchSizes = ArrayHelper.getBatchSizes( maxBatchSize );
	this.loaders = new ReactiveEntityLoader[ batchSizes.length ];
	for ( int i = 0; i < batchSizes.length; i++ ) {
		this.loaders[i] = new ReactiveEntityLoader( persister, batchSizes[i], lockOptions, factory, loadQueryInfluencers);
	}
	validate( maxBatchSize );
}