Code example for BatchFetchQueue

Methods: removeBatchLoadableEntityKey

0
		} 
		return batchFetchQueue; 
	} 
 
	public void clear() { 
		for ( Object o : proxiesByKey.values() ) { 
			final LazyInitializer li = ((HibernateProxy) o).getHibernateLazyInitializer(); 
			li.unsetSession(); 
		} 
		Map.Entry[] collectionEntryArray = IdentityMap.concurrentEntries( collectionEntries ); 
		for ( Map.Entry aCollectionEntryArray : collectionEntryArray ) { 
			((PersistentCollection) aCollectionEntryArray.getKey()).unsetSession( getSession() ); 
		} 
		arrayHolders.clear(); 
		entitiesByKey.clear(); 
		entitiesByUniqueKey.clear(); 
		entityEntries.clear(); 
		parentsByChild.clear(); 
		entitySnapshotsByKey.clear(); 
		collectionsByKey.clear(); 
		collectionEntries.clear(); 
		if ( unownedCollections != null ) { 
			unownedCollections.clear(); 
		} 
		proxiesByKey.clear(); 
		nullifiableEntityKeys.clear(); 
		if ( batchFetchQueue != null ) { 
			batchFetchQueue.clear(); 
		} 
		// defaultReadOnly is unaffected by clear() 
		hasNonReadOnlyEntities = false; 
		if ( loadContexts != null ) { 
			loadContexts.cleanup(); 
		} 
	} 
 
	/** 
	 * {@inheritDoc} 
	 */ 
	public boolean isDefaultReadOnly() { 
		return defaultReadOnly; 
	} 
 
	/** 
	 * {@inheritDoc} 
	 */ 
	public void setDefaultReadOnly(boolean defaultReadOnly) { 
		this.defaultReadOnly = defaultReadOnly; 
	} 
 
	public boolean hasNonReadOnlyEntities() { 
		return hasNonReadOnlyEntities; 
	} 
 
	public void setEntryStatus(EntityEntry entry, Status status) { 
		entry.setStatus(status); 
		setHasNonReadOnlyEnties(status); 
	} 
 
	private void setHasNonReadOnlyEnties(Status status) { 
		if ( status==Status.DELETED || status==Status.MANAGED || status==Status.SAVING ) { 
			hasNonReadOnlyEntities = true; 
		} 
	} 
 
	public void afterTransactionCompletion() { 
		cleanUpInsertedKeysAfterTransaction(); 
		// Downgrade locks 
		for ( Object o : entityEntries.values() ) { 
			((EntityEntry) o).setLockMode( LockMode.NONE ); 
		} 
	} 
 
	/** 
	 * Get the current state of the entity as known to the underlying 
	 * database, or null if there is no corresponding row 
	 */ 
	public Object[] getDatabaseSnapshot(Serializable id, EntityPersister persister) 
	throws HibernateException { 
		final EntityKey key = session.generateEntityKey( id, persister ); 
		Object cached = entitySnapshotsByKey.get(key); 
		if (cached!=null) { 
			return cached==NO_ROW ? null : (Object[]) cached; 
		} 
		else { 
			Object[] snapshot = persister.getDatabaseSnapshot( id, session ); 
			entitySnapshotsByKey.put( key, snapshot==null ? NO_ROW : snapshot ); 
			return snapshot; 
		} 
	} 
 
	public Object[] getNaturalIdSnapshot(Serializable id, EntityPersister persister) 
	throws HibernateException { 
		if ( !persister.hasNaturalIdentifier() ) { 
			return null; 
		} 
 
		// if the natural-id is marked as non-mutable, it is not retrieved during a 
		// normal database-snapshot operation... 
		int[] props = persister.getNaturalIdentifierProperties(); 
		boolean[] updateable = persister.getPropertyUpdateability(); 
		boolean allNatualIdPropsAreUpdateable = true; 
		for ( int i = 0; i < props.length; i++ ) { 
			if ( !updateable[ props[i] ] ) { 
				allNatualIdPropsAreUpdateable = false; 
				break; 
			} 
		} 
 
		if ( allNatualIdPropsAreUpdateable ) { 
			// do this when all the properties are updateable since there is 
			// a certain likelihood that the information will already be 
			// snapshot-cached. 
			Object[] entitySnapshot = getDatabaseSnapshot( id, persister ); 
			if ( entitySnapshot == NO_ROW ) { 
				return null; 
			} 
			Object[] naturalIdSnapshot = new Object[ props.length ]; 
			for ( int i = 0; i < props.length; i++ ) { 
				naturalIdSnapshot[i] = entitySnapshot[ props[i] ]; 
			} 
			return naturalIdSnapshot; 
		} 
		else { 
			return persister.getNaturalIdentifierSnapshot( id, session ); 
		} 
	} 
 
	/** 
	 * Retrieve the cached database snapshot for the requested entity key. 
	 * <p/> 
	 * This differs from {@link #getDatabaseSnapshot} is two important respects:<ol> 
	 * <li>no snapshot is obtained from the database if not already cached</li> 
	 * <li>an entry of {@link #NO_ROW} here is interpretet as an exception</li> 
	 * </ol> 
	 * @param key The entity key for which to retrieve the cached snapshot 
	 * @return The cached snapshot 
	 * @throws IllegalStateException if the cached snapshot was == {@link #NO_ROW}. 
	 */ 
	public Object[] getCachedDatabaseSnapshot(EntityKey key) { 
		Object snapshot = entitySnapshotsByKey.get( key ); 
		if ( snapshot == NO_ROW ) { 
			throw new IllegalStateException( "persistence context reported no row snapshot for " + MessageHelper.infoString( key.getEntityName(), key.getIdentifier() ) ); 
		} 
		return ( Object[] ) snapshot; 
	} 
 
	/*public void removeDatabaseSnapshot(EntityKey key) { 
		entitySnapshotsByKey.remove(key); 
	}*/ 
 
	public void addEntity(EntityKey key, Object entity) { 
		entitiesByKey.put(key, entity); 
		getBatchFetchQueue().removeBatchLoadableEntityKey(key); 
	} 
 
	/** 
	 * Get the entity instance associated with the given 
	 * <tt>EntityKey</tt> 
	 */ 
	public Object getEntity(EntityKey key) { 
		return entitiesByKey.get(key); 
	} 
 
	public boolean containsEntity(EntityKey key) { 
		return entitiesByKey.containsKey(key); 
	} 
 
	/** 
	 * Remove an entity from the session cache, also clear 
	 * up other state associated with the entity, all except 
	 * for the <tt>EntityEntry</tt> 
	 */ 
	public Object removeEntity(EntityKey key) { 
		Object entity = entitiesByKey.remove(key); 
		Iterator iter = entitiesByUniqueKey.values().iterator();