當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityPersister.isInstance方法代碼示例

本文整理匯總了Java中org.hibernate.persister.entity.EntityPersister.isInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityPersister.isInstance方法的具體用法?Java EntityPersister.isInstance怎麽用?Java EntityPersister.isInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.persister.entity.EntityPersister的用法示例。


在下文中一共展示了EntityPersister.isInstance方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: interpretEntityKey

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
public EntityKey interpretEntityKey(
		SessionImplementor session,
		String optionalEntityName,
		Serializable optionalId,
		Object optionalObject) {
	if ( optionalEntityName != null ) {
		final EntityPersister entityPersister;
		if ( optionalObject != null ) {
			entityPersister = session.getEntityPersister( optionalEntityName, optionalObject );
		}
		else {
			entityPersister = session.getFactory().getEntityPersister( optionalEntityName );
		}
		if ( entityPersister.isInstance( optionalId ) &&
				!entityPersister.getEntityMetamodel().getIdentifierProperty().isVirtual() &&
				entityPersister.getEntityMetamodel().getIdentifierProperty().isEmbedded() ) {
			// non-encapsulated composite identifier
			final Serializable identifierState = ((CompositeType) entityPersister.getIdentifierType()).getPropertyValues(
					optionalId,
					session
			);
			return session.generateEntityKey( identifierState, entityPersister );
		}
		else {
			return session.generateEntityKey( optionalId, entityPersister );
		}
	}
	else {
		return null;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:ResultSetProcessorHelper.java

示例2: loadFromSessionCache

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * Attempts to locate the entity in the session-level cache.
 * <p/>
 * If allowed to return nulls, then if the entity happens to be found in
 * the session cache, we check the entity type for proper handling
 * of entity hierarchies.
 * <p/>
 * If checkDeleted was set to true, then if the entity is found in the
 * session-level cache, it's current status within the session cache
 * is checked to see if it has previously been scheduled for deletion.
 *
 * @param event The load event
 * @param keyToLoad The EntityKey representing the entity to be loaded.
 * @param options The load options.
 *
 * @return The entity from the session-level cache, or null.
 *
 * @throws HibernateException Generally indicates problems applying a lock-mode.
 */
protected Object loadFromSessionCache(
		final LoadEvent event,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options) throws HibernateException {

	SessionImplementor session = event.getSession();
	Object old = session.getEntityUsingInterceptor( keyToLoad );

	if ( old != null ) {
		// this object was already loaded
		EntityEntry oldEntry = session.getPersistenceContext().getEntry( old );
		if ( options.isCheckDeleted() ) {
			Status status = oldEntry.getStatus();
			if ( status == Status.DELETED || status == Status.GONE ) {
				return REMOVED_ENTITY_MARKER;
			}
		}
		if ( options.isAllowNulls() ) {
			final EntityPersister persister = event.getSession()
					.getFactory()
					.getEntityPersister( keyToLoad.getEntityName() );
			if ( !persister.isInstance( old ) ) {
				return INCONSISTENT_RTN_CLASS_MARKER;
			}
		}
		upgradeLock( old, oldEntry, event.getLockOptions(), event.getSession() );
	}

	return old;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:50,代碼來源:DefaultLoadEventListener.java

示例3: getCollectionOwner

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
@Override
public Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister) throws MappingException {
	// todo : we really just need to add a split in the notions of:
	//		1) collection key
	//		2) collection owner key
	// these 2 are not always the same.  Same is true in the case of ToOne associations with property-ref...
	final EntityPersister ownerPersister = collectionPersister.getOwnerEntityPersister();
	if ( ownerPersister.getIdentifierType().getReturnedClass().isInstance( key ) ) {
		return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
	}

	// we have a property-ref type mapping for the collection key.  But that could show up a few ways here...
	//
	//		1) The incoming key could be the entity itself...
	if ( ownerPersister.isInstance( key ) ) {
		final Serializable owenerId = ownerPersister.getIdentifier( key, session );
		if ( owenerId == null ) {
			return null;
		}
		return getEntity( session.generateEntityKey( owenerId, ownerPersister ) );
	}

	final CollectionType collectionType = collectionPersister.getCollectionType();

	//		2) The incoming key is most likely the collection key which we need to resolve to the owner key
	//			find the corresponding owner instance
	//			a) try by EntityUniqueKey
	if ( collectionType.getLHSPropertyName() != null ) {
		final Object owner = getEntity(
				new EntityUniqueKey(
						ownerPersister.getEntityName(),
						collectionType.getLHSPropertyName(),
						key,
						collectionPersister.getKeyType(),
						ownerPersister.getEntityMode(),
						session.getFactory()
				)
		);
		if ( owner != null ) {
			return owner;
		}

		//		b) try by EntityKey, which means we need to resolve owner-key -> collection-key
		//			IMPL NOTE : yes if we get here this impl is very non-performant, but PersistenceContext
		//					was never designed to handle this case; adding that capability for real means splitting
		//					the notions of:
		//						1) collection key
		//						2) collection owner key
		// 					these 2 are not always the same (same is true in the case of ToOne associations with
		// 					property-ref).  That would require changes to (at least) CollectionEntry and quite
		//					probably changes to how the sql for collection initializers are generated
		//
		//			We could also possibly see if the referenced property is a natural id since we already have caching
		//			in place of natural id snapshots.  BUt really its better to just do it the right way ^^ if we start
		// 			going that route
		final Serializable ownerId = ownerPersister.getIdByUniqueKey( key, collectionType.getLHSPropertyName(), session );
		return getEntity( session.generateEntityKey( ownerId, ownerPersister ) );
	}

	// as a last resort this is what the old code did...
	return getEntity( session.generateEntityKey( key, collectionPersister.getOwnerEntityPersister() ) );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:63,代碼來源:StatefulPersistenceContext.java

示例4: loadFromSecondLevelCache

import org.hibernate.persister.entity.EntityPersister; //導入方法依賴的package包/類
/**
 * Attempts to load the entity from the second-level cache.
 *
 * @param event The load event
 * @param persister The persister for the entity being requested for load
 * @param options The load options.
 *
 * @return The entity from the second-level cache, or null.
 */
protected Object loadFromSecondLevelCache(
		final LoadEvent event,
		final EntityPersister persister,
		final LoadEventListener.LoadType options) {

	final SessionImplementor source = event.getSession();
	final boolean useCache = persister.hasCache()
			&& source.getCacheMode().isGetEnabled()
			&& event.getLockMode().lessThan( LockMode.READ );

	if ( !useCache ) {
		// we can't use cache here
		return null;
	}

	final SessionFactoryImplementor factory = source.getFactory();
	final CacheKey ck = source.generateCacheKey(
			event.getEntityId(),
			persister.getIdentifierType(),
			persister.getRootEntityName()
	);

	final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() );
	if ( factory.getStatistics().isStatisticsEnabled() ) {
		if ( ce == null ) {
			factory.getStatisticsImplementor().secondLevelCacheMiss(
					persister.getCacheAccessStrategy().getRegion().getName()
			);
		}
		else {
			factory.getStatisticsImplementor().secondLevelCacheHit(
					persister.getCacheAccessStrategy().getRegion().getName()
			);
		}
	}

	if ( ce == null ) {
		// nothing was found in cache
		return null;
	}

	CacheEntry entry = (CacheEntry) persister.getCacheEntryStructure().destructure( ce, factory );
	Object entity = convertCacheEntryToEntity( entry, event.getEntityId(), persister, event );
	
	if ( !persister.isInstance( entity ) ) {
		throw new WrongClassException(
				"loaded object was of wrong class " + entity.getClass(),
				event.getEntityId(),
				persister.getEntityName()
			);
	}
	
	return entity;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:64,代碼來源:DefaultLoadEventListener.java


注:本文中的org.hibernate.persister.entity.EntityPersister.isInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。