org.hibernate.persister.collection.QueryableCollection#getElementPersister ( )源码实例Demo

下面列出了org.hibernate.persister.collection.QueryableCollection#getElementPersister ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 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() );
	}

}
 
源代码2 项目: 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 );
}
 
源代码3 项目: lams   文件: FromElement.java
private TypeDiscriminatorMetadata buildTypeDiscriminatorMetadata() {
	final String aliasToUse = getTableAlias();
	Queryable queryable = getQueryable();
	if ( queryable == null ) {
		QueryableCollection collection = getQueryableCollection();
		if ( ! collection.getElementType().isEntityType() ) {
			throw new QueryException( "type discrimination cannot be applied to value collection [" + collection.getRole() + "]" );
		}
		queryable = (Queryable) collection.getElementPersister();
	}

	handlePropertyBeingDereferenced( getDataType(), DISCRIMINATOR_PROPERTY_NAME );

	return new TypeDiscriminatorMetadataImpl( queryable.getTypeDiscriminatorMetadata(), aliasToUse );
}
 
源代码4 项目: lams   文件: PathExpressionParser.java
public String addFromCollection(QueryTranslatorImpl q) throws QueryException {
	Type collectionElementType = getPropertyType();

	if ( collectionElementType == null ) {
		throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path );
	}

	if ( collectionElementType.isEntityType() ) {
		// an association
		QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole );
		Queryable entityPersister = ( Queryable ) collectionPersister.getElementPersister();
		String clazz = entityPersister.getEntityName();

		final String elementName;
		if ( collectionPersister.isOneToMany() ) {
			elementName = collectionName;
			//allow index() function:
			q.decoratePropertyMapping( elementName, collectionPersister );
		}
		else { //many-to-many
			q.addCollection( collectionName, collectionRole );
			elementName = q.createNameFor( clazz );
			addJoin( elementName, ( AssociationType ) collectionElementType );
		}
		q.addFrom( elementName, clazz, joinSequence );
		currentPropertyMapping = new CollectionPropertyMapping( collectionPersister );
		return elementName;
	}
	else {
		// collections of values
		q.addFromCollection( collectionName, collectionRole, joinSequence );
		return collectionName;
	}

}
 
源代码5 项目: cacheonix-core   文件: CollectionElementLoader.java
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() );

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

	super(factory, enabledFilters);

	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( new OuterJoinableAssociation( 
			oneToManyPersister.getCollectionType(),
			null, 
			null, 
			alias, 
			JoinFragment.LEFT_OUTER_JOIN, 
			getFactory(), 
			CollectionHelper.EMPTY_MAP 
		) );
	
	initPersisters(allAssociations, LockMode.NONE);
	initStatementString(elementPersister, alias, batchSize, subquery);

}
 
源代码7 项目: cacheonix-core   文件: PathExpressionParser.java
public String addFromCollection(QueryTranslatorImpl q) throws QueryException {
	Type collectionElementType = getPropertyType();

	if ( collectionElementType == null ) {
		throw new QueryException( "must specify 'elements' for collection valued property in from clause: " + path );
	}

	if ( collectionElementType.isEntityType() ) {
		// an association
		QueryableCollection collectionPersister = q.getCollectionPersister( collectionRole );
		Queryable entityPersister = ( Queryable ) collectionPersister.getElementPersister();
		String clazz = entityPersister.getEntityName();

		final String elementName;
		if ( collectionPersister.isOneToMany() ) {
			elementName = collectionName;
			//allow index() function:
			q.decoratePropertyMapping( elementName, collectionPersister );
		}
		else { //many-to-many
			q.addCollection( collectionName, collectionRole );
			elementName = q.createNameFor( clazz );
			addJoin( elementName, ( AssociationType ) collectionElementType );
		}
		q.addFrom( elementName, clazz, joinSequence );
		currentPropertyMapping = new CollectionPropertyMapping( collectionPersister );
		return elementName;
	}
	else {
		// collections of values
		q.addFromCollection( collectionName, collectionRole, joinSequence );
		return collectionName;
	}

}
 
源代码8 项目: lams   文件: JoinWalker.java
protected void initPersisters(
		final List associations,
		final LockOptions lockOptions,
		final AssociationInitCallback callback) throws MappingException {
	final int joins = countEntityPersisters( associations );
	final int collections = countCollectionPersisters( associations );

	collectionOwners = collections == 0 ? null : new int[collections];
	collectionPersisters = collections == 0 ? null : new CollectionPersister[collections];
	collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collections );

	this.lockOptions = lockOptions;

	persisters = new Loadable[joins];
	aliases = new String[joins];
	owners = new int[joins];
	ownerAssociationTypes = new EntityType[joins];
	lockModeArray = ArrayHelper.fillArray( lockOptions.getLockMode(), joins );

	int i = 0;
	int j = 0;
	for ( Object association : associations ) {
		final OuterJoinableAssociation oj = (OuterJoinableAssociation) association;
		if ( !oj.isCollection() ) {

			persisters[i] = (Loadable) oj.getJoinable();
			aliases[i] = oj.getRHSAlias();
			owners[i] = oj.getOwner( associations );
			ownerAssociationTypes[i] = (EntityType) oj.getJoinableType();
			callback.associationProcessed( oj, i );
			i++;

		}
		else {

			QueryableCollection collPersister = (QueryableCollection) oj.getJoinable();
			if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN && !oj.hasRestriction() ) {
				//it must be a collection fetch
				collectionPersisters[j] = collPersister;
				collectionOwners[j] = oj.getOwner( associations );
				j++;
			}

			if ( collPersister.isOneToMany() ) {
				persisters[i] = (Loadable) collPersister.getElementPersister();
				aliases[i] = oj.getRHSAlias();
				callback.associationProcessed( oj, i );
				i++;
			}
		}
	}

	if ( ArrayHelper.isAllNegative( owners ) ) {
		owners = null;
	}
	if ( collectionOwners != null && ArrayHelper.isAllNegative( collectionOwners ) ) {
		collectionOwners = null;
	}
}
 
源代码9 项目: lams   文件: FromElementFactory.java
FromElement createElementJoin(QueryableCollection queryableCollection) throws SemanticException {
		FromElement elem;

		implied = true; //TODO: always true for now, but not if we later decide to support elements() in the from clause
		inElementsFunction = true;
		Type elementType = queryableCollection.getElementType();
		if ( !elementType.isEntityType() ) {
			throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" );
		}
		this.queryableCollection = queryableCollection;
		SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
		FromElement destination = null;
		String tableAlias = null;
		EntityPersister entityPersister = queryableCollection.getElementPersister();
		tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
		String associatedEntityName = entityPersister.getEntityName();
		EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName );
		// Create the FROM element for the target (the elements of the collection).
		destination = createAndAddFromElement(
				associatedEntityName,
				classAlias,
				targetEntityPersister,
				(EntityType) queryableCollection.getElementType(),
				tableAlias
		);
		// If the join is implied, then don't include sub-classes on the element.
		if ( implied ) {
			destination.setIncludeSubclasses( false );
		}
		fromClause.addCollectionJoinFromElementByPath( path, destination );
//		origin.addDestination(destination);
		// Add the query spaces.
		fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );

		CollectionType type = queryableCollection.getCollectionType();
		String role = type.getRole();
		String roleAlias = origin.getTableAlias();

		String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias );
		AssociationType elementAssociationType = sfh.getElementAssociationType( type );

		// Create the join element under the from element.
		JoinType joinType = JoinType.INNER_JOIN;
		JoinSequence joinSequence = sfh.createJoinSequence(
				implied,
				elementAssociationType,
				tableAlias,
				joinType,
				targetColumns
		);
		elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
		elem.setUseFromFragment( true );    // The associated entity is implied, but it must be included in the FROM.
		elem.setCollectionTableAlias( roleAlias );    // The collection alias is the role.
		return elem;
	}
 
源代码10 项目: cacheonix-core   文件: JoinWalker.java
protected void initPersisters(final List associations, final LockMode lockMode) throws MappingException {
	
	final int joins = countEntityPersisters(associations);
	final int collections = countCollectionPersisters(associations);

	collectionOwners = collections==0 ? null : new int[collections];
	collectionPersisters = collections==0 ? null : new CollectionPersister[collections];
	collectionSuffixes = BasicLoader.generateSuffixes( joins + 1, collections );

	persisters = new Loadable[joins];
	aliases = new String[joins];
	owners = new int[joins];
	ownerAssociationTypes = new EntityType[joins];
	lockModeArray = ArrayHelper.fillArray(lockMode, joins);
	
	int i=0;
	int j=0;
	Iterator iter = associations.iterator();
	while ( iter.hasNext() ) {
		final OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
		if ( !oj.isCollection() ) {
			
			persisters[i] = (Loadable) oj.getJoinable();
			aliases[i] = oj.getRHSAlias();
			owners[i] = oj.getOwner(associations);
			ownerAssociationTypes[i] = (EntityType) oj.getJoinableType();
			i++;
			
		}
		else {
			
			QueryableCollection collPersister = (QueryableCollection) oj.getJoinable();
			if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) {
				//it must be a collection fetch
				collectionPersisters[j] = collPersister;
				collectionOwners[j] = oj.getOwner(associations);
				j++;
			}

			if ( collPersister.isOneToMany() ) {
				persisters[i] = (Loadable) collPersister.getElementPersister();
				aliases[i] = oj.getRHSAlias();
				i++;
			}
		}
	}

	if ( ArrayHelper.isAllNegative(owners) ) owners = null;
	if ( collectionOwners!=null && ArrayHelper.isAllNegative(collectionOwners) ) {
		collectionOwners = null;
	}
}
 
源代码11 项目: cacheonix-core   文件: FromElementFactory.java
FromElement createElementJoin(QueryableCollection queryableCollection) throws SemanticException {
		FromElement elem;

		implied = true; //TODO: always true for now, but not if we later decide to support elements() in the from clause
		inElementsFunction = true;
		Type elementType = queryableCollection.getElementType();
		if ( !elementType.isEntityType() ) {
			throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" );
		}
		this.queryableCollection = queryableCollection;
		SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
		FromElement destination = null;
		String tableAlias = null;
		EntityPersister entityPersister = queryableCollection.getElementPersister();
		tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
		String associatedEntityName = entityPersister.getEntityName();
		EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName );
		// Create the FROM element for the target (the elements of the collection).
		destination = createAndAddFromElement( 
				associatedEntityName,
				classAlias,
				targetEntityPersister,
				( EntityType ) queryableCollection.getElementType(),
				tableAlias
			);
		// If the join is implied, then don't include sub-classes on the element.
		if ( implied ) {
			destination.setIncludeSubclasses( false );
		}
		fromClause.addCollectionJoinFromElementByPath( path, destination );
//		origin.addDestination(destination);
		// Add the query spaces.
		fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );

		CollectionType type = queryableCollection.getCollectionType();
		String role = type.getRole();
		String roleAlias = origin.getTableAlias();

		String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias );
		AssociationType elementAssociationType = sfh.getElementAssociationType( type );

		// Create the join element under the from element.
		int joinType = JoinFragment.INNER_JOIN;
		JoinSequence joinSequence = sfh.createJoinSequence( implied, elementAssociationType, tableAlias, joinType, targetColumns );
		elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
		elem.setUseFromFragment( true );	// The associated entity is implied, but it must be included in the FROM.
		elem.setCollectionTableAlias( roleAlias );	// The collection alias is the role.
		return elem;
	}