当前位置: 首页>>代码示例>>Java>>正文


Java CollectionType.getRole方法代码示例

本文整理汇总了Java中org.hibernate.type.CollectionType.getRole方法的典型用法代码示例。如果您正苦于以下问题:Java CollectionType.getRole方法的具体用法?Java CollectionType.getRole怎么用?Java CollectionType.getRole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.hibernate.type.CollectionType的用法示例。


在下文中一共展示了CollectionType.getRole方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveIndex

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
public void resolveIndex(AST parent) throws SemanticException {
	// An ident node can represent an index expression if the ident
	// represents a naked property ref
	//      *Note: this makes the assumption (which is currently the case
	//      in the hql-sql grammar) that the ident is first resolved
	//      itself (addrExpr -> resolve()).  The other option, if that
	//      changes, is to call resolve from here; but it is
	//      currently un-needed overhead.
	if (!(isResolved() && nakedPropertyRef)) {
		throw new UnsupportedOperationException();
	}

	String propertyName = getOriginalText();
	if (!getDataType().isCollectionType()) {
		throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
	}

	// TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
	CollectionType type = (CollectionType) getDataType();
	String role = type.getRole();
	QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);

	String alias = null;  // DotNode uses null here...
	String columnTableAlias = getFromElement().getTableAlias();
	JoinType joinType = JoinType.INNER_JOIN;
	boolean fetch = false;

	FromElementFactory factory = new FromElementFactory(
			getWalker().getCurrentFromClause(),
			getFromElement(),
			propertyName,
			alias,
			getFromElement().toColumns(columnTableAlias, propertyName, false),
			true
	);
	FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
	setFromElement(elem);
	getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());	// Always add the collection's query spaces.
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:IdentNode.java

示例2: resolveIndex

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
public void resolveIndex(AST parent) throws SemanticException {
	// An ident node can represent an index expression if the ident
	// represents a naked property ref
	//      *Note: this makes the assumption (which is currently the case
	//      in the hql-sql grammar) that the ident is first resolved
	//      itself (addrExpr -> resolve()).  The other option, if that
	//      changes, is to call resolve from here; but it is
	//      currently un-needed overhead.
	if (!(isResolved() && nakedPropertyRef)) {
		throw new UnsupportedOperationException();
	}

	String propertyName = getOriginalText();
	if (!getDataType().isCollectionType()) {
		throw new SemanticException("Collection expected; [" + propertyName + "] does not refer to a collection property");
	}

	// TODO : most of below was taken verbatim from DotNode; should either delegate this logic or super-type it
	CollectionType type = (CollectionType) getDataType();
	String role = type.getRole();
	QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection(role);

	String alias = null;  // DotNode uses null here...
	String columnTableAlias = getFromElement().getTableAlias();
	int joinType = JoinFragment.INNER_JOIN;
	boolean fetch = false;

	FromElementFactory factory = new FromElementFactory(
			getWalker().getCurrentFromClause(),
			getFromElement(),
			propertyName,
			alias,
			getFromElement().toColumns(columnTableAlias, propertyName, false),
			true
	);
	FromElement elem = factory.createCollection(queryableCollection, role, joinType, fetch, true);
	setFromElement(elem);
	getWalker().addQuerySpaces(queryableCollection.getCollectionSpaces());	// Always add the collection's query spaces.
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:40,代码来源:IdentNode.java

示例3: getPathInfo

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
private CriteriaInfoProvider getPathInfo(String path) {
	StringTokenizer tokens = new StringTokenizer( path, "." );
	String componentPath = "";

	// start with the 'rootProvider'
	CriteriaInfoProvider provider = nameCriteriaInfoMap.get( rootEntityName );

	while ( tokens.hasMoreTokens() ) {
		componentPath += tokens.nextToken();
		final Type type = provider.getType( componentPath );
		if ( type.isAssociationType() ) {
			// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
			final AssociationType atype = (AssociationType) type;
			final CollectionType ctype = type.isCollectionType() ? (CollectionType)type : null;
			final Type elementType = (ctype != null) ? ctype.getElementType( sessionFactory ) : null;
			// is the association a collection of components or value-types? (i.e a colloction of valued types?)
			if ( ctype != null  && elementType.isComponentType() ) {
				provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister(ctype.getRole()) );
			}
			else if ( ctype != null && !elementType.isEntityType() ) {
				provider = new ScalarCollectionCriteriaInfoProvider( helper, ctype.getRole() );
			}
			else {
				provider = new EntityCriteriaInfoProvider(
						(Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) )
				);
			}
			
			componentPath = "";
		}
		else if ( type.isComponentType() ) {
			if (!tokens.hasMoreTokens()) {
				throw new QueryException(
						"Criteria objects cannot be created directly on components.  Create a criteria on " +
								"owning entity and use a dotted property to access component property: " + path
				);
			}
			else {
				componentPath += '.';
			}
		}
		else {
			throw new QueryException( "not an association: " + componentPath );
		}
	}
	
	return provider;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:CriteriaQueryTranslator.java

示例4: processReachableCollection

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
/**
    * Initialize the role of the collection.
    *
    * @param collection The collection to be updated by reachability.
    * @param type The type of the collection.
    * @param entity The owner of the collection.
 * @param session The session from which this request originates
    */
public static void processReachableCollection(
		PersistentCollection collection,
		CollectionType type,
		Object entity,
		SessionImplementor session) {
	collection.setOwner( entity );
	final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( collection );

	if ( ce == null ) {
		// refer to comment in StatefulPersistenceContext.addCollection()
		throw new HibernateException(
				"Found two representations of same collection: " +
				type.getRole()
		);
	}

	// The CollectionEntry.isReached() stuff is just to detect any silly users
	// who set up circular or shared references between/to collections.
	if ( ce.isReached() ) {
		// We've been here before
		throw new HibernateException(
				"Found shared references to a collection: " + type.getRole()
		);
	}
	ce.setReached( true );

	final SessionFactoryImplementor factory = session.getFactory();
	final CollectionPersister persister = factory.getCollectionPersister( type.getRole() );
	ce.setCurrentPersister( persister );
	//TODO: better to pass the id in as an argument?
	ce.setCurrentKey( type.getKeyOfOwner( entity, session ) );

	if ( LOG.isDebugEnabled() ) {
		if ( collection.wasInitialized() ) {
			LOG.debugf(
					"Collection found: %s, was: %s (initialized)",
					MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ),
					MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session )
			);
		}
		else {
			LOG.debugf(
					"Collection found: %s, was: %s (uninitialized)",
					MessageHelper.collectionInfoString( persister, collection, ce.getCurrentKey(), session ),
					MessageHelper.collectionInfoString( ce.getLoadedPersister(), collection, ce.getLoadedKey(), session )
			);
		}
	}

	prepareCollectionForUpdate( collection, ce, factory );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:60,代码来源:Collections.java

示例5: dereferenceCollection

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
private void dereferenceCollection(
		CollectionType collectionType,
		boolean implicitJoin,
		boolean indexed,
		String classAlias,
		AST parent)
		throws SemanticException {

	dereferenceType = DereferenceType.COLLECTION;
	String role = collectionType.getRole();

	//foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness)
	boolean isSizeProperty = getNextSibling() != null &&
			CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() );

	if ( isSizeProperty ) {
		indexed = true; //yuck!
	}

	QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection( role );
	String propName = getPath();
	FromClause currentFromClause = getWalker().getCurrentFromClause();

	// determine whether we should use the table name or table alias to qualify the column names...
	// we need to use the table-name when:
	//		1) the top-level statement is not a SELECT
	//		2) the LHS FromElement is *the* FromElement from the top-level statement
	//
	// there is a caveat here.. if the update/delete statement are "multi-table" we should continue to use
	// the alias also, even if the FromElement is the root one...
	//
	// in all other cases, we should use the table alias
	final FromElement lhsFromElement = getLhs().getFromElement();
	if ( getWalker().getStatementType() != SqlTokenTypes.SELECT ) {
		if ( isFromElementUpdateOrDeleteRoot( lhsFromElement ) ) {
			// at this point we know we have the 2 conditions above,
			// lets see if we have the mentioned "multi-table" caveat...
			boolean useAlias = false;
			if ( getWalker().getStatementType() != SqlTokenTypes.INSERT ) {
				final Queryable persister = lhsFromElement.getQueryable();
				if ( persister.isMultiTable() ) {
					useAlias = true;
				}
			}
			if ( !useAlias ) {
				final String lhsTableName = lhsFromElement.getQueryable().getTableName();
				columns = getFromElement().toColumns( lhsTableName, propertyPath, false, true );
			}
		}
	}

	// We do not look for an existing join on the same path, because
	// it makes sense to join twice on the same collection role
	FromElementFactory factory = new FromElementFactory(
			currentFromClause,
			getLhs().getFromElement(),
			propName,
			classAlias,
			getColumns(),
			implicitJoin
	);
	FromElement elem = factory.createCollection( queryableCollection, role, joinType, fetch, indexed );

	LOG.debugf( "dereferenceCollection() : Created new FROM element for %s : %s", propName, elem );

	setImpliedJoin( elem );
	setFromElement( elem );    // This 'dot' expression now refers to the resulting from element.

	if ( isSizeProperty ) {
		elem.setText( "" );
		elem.setUseWhereFragment( false );
	}

	if ( !implicitJoin ) {
		EntityPersister entityPersister = elem.getEntityPersister();
		if ( entityPersister != null ) {
			getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
		}
	}
	getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() );    // Always add the collection's query spaces.
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:82,代码来源:DotNode.java

示例6: createElementJoin

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
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;
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:56,代码来源:FromElementFactory.java

示例7: getPathInfo

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
private CriteriaInfoProvider getPathInfo(String path) {
	StringTokenizer tokens = new StringTokenizer( path, "." );
	String componentPath = "";

	// start with the 'rootProvider'
	CriteriaInfoProvider provider = nameCriteriaInfoMap.get( rootEntityName );

	while ( tokens.hasMoreTokens() ) {
		componentPath += tokens.nextToken();
		final Type type = provider.getType( componentPath );
		if ( type.isAssociationType() ) {
			// CollectionTypes are always also AssociationTypes - but there's not always an associated entity...
			final AssociationType atype = (AssociationType) type;
			final CollectionType ctype = type.isCollectionType() ? (CollectionType) type : null;
			final Type elementType = ( ctype != null ) ? ctype.getElementType( sessionFactory ) : null;
			// is the association a collection of components or value-types? (i.e a colloction of valued types?)
			if ( ctype != null && elementType.isComponentType() ) {
				provider = new ComponentCollectionCriteriaInfoProvider( helper.getCollectionPersister( ctype.getRole() ) );
			}
			else if ( ctype != null && !elementType.isEntityType() ) {
				provider = new ScalarCollectionCriteriaInfoProvider( helper, ctype.getRole() );
			}
			else {
				provider = new EntityCriteriaInfoProvider(
						(Queryable) sessionFactory.getEntityPersister( atype.getAssociatedEntityName( sessionFactory ) )
				);
			}

			componentPath = "";
		}
		else if ( type.isComponentType() ) {
			if ( !tokens.hasMoreTokens() ) {
				throw new QueryException(
						"Criteria objects cannot be created directly on components.  Create a criteria on " +
								"owning entity and use a dotted property to access component property: " + path
				);
			}
			else {
				componentPath += '.';
			}
		}
		else {
			throw new QueryException( "not an association: " + componentPath );
		}
	}

	return provider;
}
 
开发者ID:geodir,项目名称:Layer-Query,代码行数:49,代码来源:CustomCriteriaQueryTranslator.java

示例8: processReachableCollection

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
/**
 * Initialize the role of the collection.
 *
 * @param collection The collection to be updated by reachibility.
 * @param type The type of the collection.
 * @param entity The owner of the collection.
 * @throws HibernateException
 */
public static void processReachableCollection(
		PersistentCollection collection,
        CollectionType type,
        Object entity,
        SessionImplementor session)
throws HibernateException {

	collection.setOwner(entity);

	CollectionEntry ce = session.getPersistenceContext().getCollectionEntry(collection);

	if ( ce == null ) {
		// refer to comment in StatefulPersistenceContext.addCollection()
		throw new HibernateException(
				"Found two representations of same collection: " +
				type.getRole()
		);
	}

	// The CollectionEntry.isReached() stuff is just to detect any silly users  
	// who set up circular or shared references between/to collections.
	if ( ce.isReached() ) {
		// We've been here before
		throw new HibernateException(
				"Found shared references to a collection: " +
				type.getRole()
		);
	}
	ce.setReached(true);

	SessionFactoryImplementor factory = session.getFactory();
	CollectionPersister persister = factory.getCollectionPersister( type.getRole() );
	ce.setCurrentPersister(persister);
	ce.setCurrentKey( type.getKeyOfOwner(entity, session) ); //TODO: better to pass the id in as an argument?

	if ( log.isDebugEnabled() ) {
		log.debug(
				"Collection found: " +
				MessageHelper.collectionInfoString( persister, ce.getCurrentKey(), factory ) +
				", was: " +
				MessageHelper.collectionInfoString( ce.getLoadedPersister(), ce.getLoadedKey(), factory ) +
				( collection.wasInitialized() ? " (initialized)" : " (uninitialized)" )
		);
	}

	prepareCollectionForUpdate( collection, ce, session.getEntityMode(), factory );

}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:57,代码来源:Collections.java

示例9: dereferenceCollection

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
private void dereferenceCollection(CollectionType collectionType, boolean implicitJoin, boolean indexed, String classAlias, AST parent)
throws SemanticException {
	
	dereferenceType = DEREF_COLLECTION;
	String role = collectionType.getRole();
	
	//foo.bars.size (also handles deprecated stuff like foo.bars.maxelement for backwardness)
	boolean isSizeProperty = getNextSibling()!=null && 
		CollectionProperties.isAnyCollectionProperty( getNextSibling().getText() );

	if ( isSizeProperty ) indexed = true; //yuck!

	QueryableCollection queryableCollection = getSessionFactoryHelper().requireQueryableCollection( role );
	String propName = getPath();
	FromClause currentFromClause = getWalker().getCurrentFromClause();

	if ( getWalker().getStatementType() != SqlTokenTypes.SELECT && indexed && classAlias == null ) {
		// should indicate that we are processing an INSERT/UPDATE/DELETE
		// query with a subquery implied via a collection property
		// function. Here, we need to use the table name itself as the
		// qualification alias.
		// TODO : verify this works for all databases...
		// TODO : is this also the case in non-"indexed" scenarios?
		String alias = getLhs().getFromElement().getQueryable().getTableName();
		columns = getFromElement().toColumns( alias, propertyPath, false, true );
	}

	//We do not look for an existing join on the same path, because
	//it makes sense to join twice on the same collection role
	FromElementFactory factory = new FromElementFactory(
	        currentFromClause,
	        getLhs().getFromElement(),
	        propName,
			classAlias,
	        getColumns(),
	        implicitJoin
	);
	FromElement elem = factory.createCollection( queryableCollection, role, joinType, fetch, indexed );
	
	if ( log.isDebugEnabled() ) {
		log.debug( "dereferenceCollection() : Created new FROM element for " + propName + " : " + elem );
	}
	
	setImpliedJoin( elem );
	setFromElement( elem );	// This 'dot' expression now refers to the resulting from element.
	
	if ( isSizeProperty ) {
		elem.setText("");
		elem.setUseWhereFragment(false);
	}
	
	if ( !implicitJoin ) {
		EntityPersister entityPersister = elem.getEntityPersister();
		if ( entityPersister != null ) {
			getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
		}
	}
	getWalker().addQuerySpaces( queryableCollection.getCollectionSpaces() );	// Always add the collection's query spaces.
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:60,代码来源:DotNode.java

示例10: createElementJoin

import org.hibernate.type.CollectionType; //导入方法依赖的package包/类
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;
	}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:50,代码来源:FromElementFactory.java


注:本文中的org.hibernate.type.CollectionType.getRole方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。