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


Java SessionFactoryImplementor.getCollectionPersister方法代码示例

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


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

示例1: getQueryableCollection

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
protected QueryableCollection getQueryableCollection(
		String entityName,
		String propertyName,
		SessionFactoryImplementor factory) throws HibernateException {
	final PropertyMapping ownerMapping = (PropertyMapping) factory.getEntityPersister( entityName );
	final Type type = ownerMapping.toType( propertyName );
	if ( !type.isCollectionType() ) {
		throw new MappingException(
				"Property path [" + entityName + "." + propertyName + "] does not reference a collection"
		);
	}

	final String role = ( (CollectionType) type ).getRole();
	try {
		return (QueryableCollection) factory.getCollectionPersister( role );
	}
	catch ( ClassCastException cce ) {
		throw new QueryException( "collection role is not queryable: " + role );
	}
	catch ( Exception e ) {
		throw new QueryException( "collection role not found: " + role );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:AbstractEmptinessExpression.java

示例2: getAssociatedEntityName

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
@Override
public String getAssociatedEntityName(SessionFactoryImplementor factory)
		throws MappingException {
	try {
		
		QueryableCollection collectionPersister = (QueryableCollection) factory
				.getCollectionPersister( role );
		
		if ( !collectionPersister.getElementType().isEntityType() ) {
			throw new MappingException( 
					"collection was not an association: " + 
					collectionPersister.getRole() 
				);
		}
		
		return collectionPersister.getElementPersister().getEntityName();
		
	}
	catch (ClassCastException cce) {
		throw new MappingException( "collection role is not queryable " + role );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:CollectionType.java

示例3: BulkOperationCleanupAction

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
/**
 * Constructs an action to cleanup "affected cache regions" based on the
 * affected entity persisters.  The affected regions are defined as the
 * region (if any) of the entity persisters themselves, plus the
 * collection regions for any collection in which those entity
 * persisters participate as elements/keys/etc.
 *
 * @param session The session to which this request is tied.
 * @param affectedQueryables The affected entity persisters.
 */
public BulkOperationCleanupAction(SessionImplementor session, Queryable... affectedQueryables) {
	final SessionFactoryImplementor factory = session.getFactory();
	final LinkedHashSet<String> spacesList = new LinkedHashSet<String>();
	for ( Queryable persister : affectedQueryables ) {
		spacesList.addAll( Arrays.asList( (String[]) persister.getQuerySpaces() ) );

		if ( persister.hasCache() ) {
			entityCleanups.add( new EntityCleanup( persister.getCacheAccessStrategy() ) );
		}
		if ( persister.hasNaturalIdentifier() && persister.hasNaturalIdCache() ) {
			naturalIdCleanups.add( new NaturalIdCleanup( persister.getNaturalIdCacheAccessStrategy() ) );
		}

		final Set<String> roles = factory.getCollectionRolesByEntityParticipant( persister.getEntityName() );
		if ( roles != null ) {
			for ( String role : roles ) {
				final CollectionPersister collectionPersister = factory.getCollectionPersister( role );
				if ( collectionPersister.hasCache() ) {
					collectionCleanups.add( new CollectionCleanup( collectionPersister.getCacheAccessStrategy() ) );
				}
			}
		}
	}

	this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:BulkOperationCleanupAction.java

示例4: processReachableCollection

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的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: evictCache

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
private void evictCache(Object entity, EntityPersister persister, EventSource session, Object[] oldState) {
	try {
		SessionFactoryImplementor factory = persister.getFactory();

		Set<String> collectionRoles = factory.getCollectionRolesByEntityParticipant( persister.getEntityName() );
		if ( collectionRoles == null || collectionRoles.isEmpty() ) {
			return;
		}
		for ( String role : collectionRoles ) {
			CollectionPersister collectionPersister = factory.getCollectionPersister( role );
			if ( !collectionPersister.hasCache() ) {
				// ignore collection if no caching is used
				continue;
			}
			// this is the property this OneToMany relation is mapped by
			String mappedBy = collectionPersister.getMappedByProperty();
			if ( mappedBy != null ) {
				int i = persister.getEntityMetamodel().getPropertyIndex( mappedBy );
				Serializable oldId = null;
				if ( oldState != null ) {
					// in case of updating an entity we perhaps have to decache 2 entity collections, this is the
					// old one
					oldId = session.getIdentifier( oldState[i] );
				}
				Object ref = persister.getPropertyValue( entity, i );
				Serializable id = null;
				if ( ref != null ) {
					id = session.getIdentifier( ref );
				}
				// only evict if the related entity has changed
				if ( id != null && !id.equals( oldId ) ) {
					evict( id, collectionPersister, session );
					if ( oldId != null ) {
						evict( oldId, collectionPersister, session );
					}
				}
			}
			else {
				LOG.debug( "Evict CollectionRegion " + role );
				collectionPersister.getCacheAccessStrategy().evictAll();
			}
		}
	}
	catch ( Exception e ) {
		// don't let decaching influence other logic
		LOG.error( "", e );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:CollectionCacheInvalidator.java

示例6: TableBasedDeleteHandlerImpl

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
public TableBasedDeleteHandlerImpl(
		SessionFactoryImplementor factory,
		HqlSqlWalker walker,
		String catalog,
		String schema) {
	super( factory, walker, catalog, schema );

	DeleteStatement deleteStatement = ( DeleteStatement ) walker.getAST();
	FromElement fromElement = deleteStatement.getFromClause().getFromElement();

	this.targetedPersister = fromElement.getQueryable();
	final String bulkTargetAlias = fromElement.getTableAlias();

	final ProcessedWhereClause processedWhereClause = processWhereClause( deleteStatement.getWhereClause() );
	this.idSelectParameterSpecifications = processedWhereClause.getIdSelectParameterSpecifications();
	this.idInsertSelect = generateIdInsertSelect( targetedPersister, bulkTargetAlias, processedWhereClause );
	log.tracev( "Generated ID-INSERT-SELECT SQL (multi-table delete) : {0}", idInsertSelect );
	
	final String idSubselect = generateIdSubselect( targetedPersister );
	deletes = new ArrayList<String>();
	
	// If many-to-many, delete the FK row in the collection table.
	// This partially overlaps with DeleteExecutor, but it instead uses the temp table in the idSubselect.
	for ( Type type : targetedPersister.getPropertyTypes() ) {
		if ( type.isCollectionType() ) {
			CollectionType cType = (CollectionType) type;
			AbstractCollectionPersister cPersister = (AbstractCollectionPersister)factory.getCollectionPersister( cType.getRole() );
			if ( cPersister.isManyToMany() ) {
				deletes.add( generateDelete( cPersister.getTableName(),
						cPersister.getKeyColumnNames(), idSubselect, "bulk delete - m2m join table cleanup"));
			}
		}
	}

	String[] tableNames = targetedPersister.getConstraintOrderedTableNameClosure();
	String[][] columnNames = targetedPersister.getContraintOrderedTableKeyColumnClosure();
	for ( int i = 0; i < tableNames.length; i++ ) {
		// TODO : an optimization here would be to consider cascade deletes and not gen those delete statements;
		//      the difficulty is the ordering of the tables here vs the cascade attributes on the persisters ->
		//          the table info gotten here should really be self-contained (i.e., a class representation
		//          defining all the needed attributes), then we could then get an array of those
		deletes.add( generateDelete( tableNames[i], columnNames[i], idSubselect, "bulk delete"));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:45,代码来源:TableBasedDeleteHandlerImpl.java

示例7: DeleteExecutor

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
public DeleteExecutor(HqlSqlWalker walker, Queryable persister) {
	super( walker, persister );
	
	final SessionFactoryImplementor factory = walker.getSessionFactoryHelper().getFactory();
	final Dialect dialect = factory.getDialect();
	
	try {
		final DeleteStatement deleteStatement = (DeleteStatement) walker.getAST();
		
		final String idSubselectWhere;
		if ( deleteStatement.hasWhereClause() ) {
			final AST whereClause = deleteStatement.getWhereClause();
			final SqlGenerator gen = new SqlGenerator( factory );
			gen.whereClause( whereClause );
			parameterSpecifications = gen.getCollectedParameters();
			idSubselectWhere = gen.getSQL().length() > 7 ? gen.getSQL() : "";
		}
		else {
			parameterSpecifications = new ArrayList<ParameterSpecification>();
			idSubselectWhere = "";
		}
		
		// If many-to-many, delete the FK row in the collection table.
		for ( Type type : persister.getPropertyTypes() ) {
			if ( type.isCollectionType() ) {
				final CollectionType cType = (CollectionType) type;
				final AbstractCollectionPersister cPersister = (AbstractCollectionPersister) factory
						.getCollectionPersister( cType.getRole() );
				if ( cPersister.isManyToMany() ) {
					if ( persister.getIdentifierColumnNames().length > 1
							&& !dialect.supportsTuplesInSubqueries() ) {
						LOG.warn(
								"This dialect is unable to cascade the delete into the many-to-many join table" +
								" when the entity has multiple primary keys.  Either properly setup cascading on" +
								" the constraints or manually clear the associations prior to deleting the entities."
						);
					}
					else {
						final String idSubselect = "(select "
								+ StringHelper.join( ", ", persister.getIdentifierColumnNames() ) + " from "
								+ persister.getTableName() + idSubselectWhere + ")";
						final String where = "(" + StringHelper.join( ", ", cPersister.getKeyColumnNames() )
								+ ") in " + idSubselect;
						final Delete delete = new Delete().setTableName( cPersister.getTableName() ).setWhere( where );
						if ( factory.getSettings().isCommentsEnabled() ) {
							delete.setComment( "delete FKs in join table" );
						}
						deletes.add( delete.toStatementString() );
					}
				}
			}
		}
	}
	catch (RecognitionException e) {
		throw new HibernateException( "Unable to delete the FKs in the join table!", e );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:58,代码来源:DeleteExecutor.java

示例8: getAssociatedJoinable

import org.hibernate.engine.spi.SessionFactoryImplementor; //导入方法依赖的package包/类
@Override
public Joinable getAssociatedJoinable(SessionFactoryImplementor factory)
		throws MappingException {
	return (Joinable) factory.getCollectionPersister( role );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:6,代码来源:CollectionType.java


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