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


Java EntityPersister.hasNaturalIdentifier方法代码示例

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


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

示例1: cacheNaturalIdCrossReferenceFromLoad

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public void cacheNaturalIdCrossReferenceFromLoad(
		EntityPersister persister,
		Serializable id,
		Object[] naturalIdValues) {
	if ( !persister.hasNaturalIdentifier() ) {
		// nothing to do
		return;
	}

	persister = locateProperPersister( persister );

	// 'justAddedLocally' is meant to handle the case where we would get double stats jounaling
	//	from a single load event.  The first put journal would come from the natural id resolution;
	// the second comes from the entity loading.  In this condition, we want to avoid the multiple
	// 'put' stats incrementing.
	final boolean justAddedLocally = naturalIdXrefDelegate.cacheNaturalIdCrossReference( persister, id, naturalIdValues );

	if ( justAddedLocally && persister.hasNaturalIdCache() ) {
		managedSharedCacheEntries( persister, id, naturalIdValues, null, CachedNaturalIdValueSource.LOAD );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:StatefulPersistenceContext.java

示例2: manageLocalNaturalIdCrossReference

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public void manageLocalNaturalIdCrossReference(
		EntityPersister persister,
		Serializable id,
		Object[] state,
		Object[] previousState,
		CachedNaturalIdValueSource source) {
	if ( !persister.hasNaturalIdentifier() ) {
		// nothing to do
		return;
	}

	persister = locateProperPersister( persister );
	final Object[] naturalIdValues = extractNaturalIdValues( state, persister );

	// cache
	naturalIdXrefDelegate.cacheNaturalIdCrossReference( persister, id, naturalIdValues );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:StatefulPersistenceContext.java

示例3: manageSharedNaturalIdCrossReference

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public void manageSharedNaturalIdCrossReference(
		EntityPersister persister,
		final Serializable id,
		Object[] state,
		Object[] previousState,
		CachedNaturalIdValueSource source) {
	if ( !persister.hasNaturalIdentifier() ) {
		// nothing to do
		return;
	}

	if ( !persister.hasNaturalIdCache() ) {
		// nothing to do
		return;
	}

	persister = locateProperPersister( persister );
	final Object[] naturalIdValues = extractNaturalIdValues( state, persister );
	final Object[] previousNaturalIdValues = previousState == null ? null : extractNaturalIdValues( previousState, persister );

	managedSharedCacheEntries( persister, id, naturalIdValues, previousNaturalIdValues, source );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:StatefulPersistenceContext.java

示例4: removeLocalNaturalIdCrossReference

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public Object[] removeLocalNaturalIdCrossReference(EntityPersister persister, Serializable id, Object[] state) {
	if ( !persister.hasNaturalIdentifier() ) {
		// nothing to do
		return null;
	}

	persister = locateProperPersister( persister );
	final Object[] naturalIdValues = getNaturalIdValues( state, persister );

	final Object[] localNaturalIdValues = naturalIdXrefDelegate.removeNaturalIdCrossReference( 
			persister, 
			id, 
			naturalIdValues 
	);

	return localNaturalIdValues != null ? localNaturalIdValues : naturalIdValues;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:StatefulPersistenceContext.java

示例5: removeSharedNaturalIdCrossReference

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
		public void removeSharedNaturalIdCrossReference(EntityPersister persister, Serializable id, Object[] naturalIdValues) {
			if ( !persister.hasNaturalIdentifier() ) {
				// nothing to do
				return;
			}

			if ( ! persister.hasNaturalIdCache() ) {
				// nothing to do
				return;
			}

			// todo : couple of things wrong here:
			//		1) should be using access strategy, not plain evict..
			//		2) should prefer session-cached values if any (requires interaction from removeLocalNaturalIdCrossReference

			persister = locateProperPersister( persister );
			final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy();
			final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session );
			naturalIdCacheAccessStrategy.evict( naturalIdCacheKey );

//			if ( sessionCachedNaturalIdValues != null
//					&& !Arrays.equals( sessionCachedNaturalIdValues, deletedNaturalIdValues ) ) {
//				final NaturalIdCacheKey sessionNaturalIdCacheKey = new NaturalIdCacheKey( sessionCachedNaturalIdValues, persister, session );
//				naturalIdCacheAccessStrategy.evict( sessionNaturalIdCacheKey );
//			}
		}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:StatefulPersistenceContext.java

示例6: handleSynchronization

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public void handleSynchronization(EntityPersister persister, Serializable pk, Object entity) {
	if ( !persister.hasNaturalIdentifier() ) {
		// nothing to do
		return;
	}

	persister = locateProperPersister( persister );

	final Object[] naturalIdValuesFromCurrentObjectState = extractNaturalIdValues( entity, persister );
	final boolean changed = ! naturalIdXrefDelegate.sameAsCached(
			persister,
			pk,
			naturalIdValuesFromCurrentObjectState
	);

	if ( changed ) {
		final Object[] cachedNaturalIdValues = naturalIdXrefDelegate.findCachedNaturalId( persister, pk );
		naturalIdXrefDelegate.cacheNaturalIdCrossReference( persister, pk, naturalIdValuesFromCurrentObjectState );
		naturalIdXrefDelegate.stashInvalidNaturalIdReference( persister, cachedNaturalIdValues );

		removeSharedNaturalIdCrossReference(
				persister,
				pk,
				cachedNaturalIdValues
		);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:StatefulPersistenceContext.java

示例7: BaseNaturalIdLoadAccessImpl

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
private BaseNaturalIdLoadAccessImpl(EntityPersister entityPersister) {
	this.entityPersister = entityPersister;

	if ( ! entityPersister.hasNaturalIdentifier() ) {
		throw new HibernateException(
				String.format( "Entity [%s] did not define a natural id", entityPersister.getEntityName() )
		);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:SessionImpl.java

示例8: doEvict

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
protected void doEvict(
		final Object object,
		final EntityKey key,
		final EntityPersister persister,
		final EventSource session)
		throws HibernateException {

	if ( LOG.isTraceEnabled() ) {
		LOG.tracev( "Evicting {0}", MessageHelper.infoString( persister ) );
	}

	if ( persister.hasNaturalIdentifier() ) {
		session.getPersistenceContext().getNaturalIdHelper().handleEviction(
				object,
				persister,
				key.getIdentifier()
		);
	}

	// remove all collections for the entity from the session-level cache
	if ( persister.hasCollections() ) {
		new EvictVisitor( session ).process( object, persister );
	}

	// remove any snapshot, not really for memory management purposes, but
	// rather because it might now be stale, and there is no longer any
	// EntityEntry to take precedence
	// This is now handled by removeEntity()
	//session.getPersistenceContext().removeDatabaseSnapshot(key);

	new Cascade( CascadingActions.EVICT, CascadePoint.AFTER_EVICT, session ).cascade( persister, object );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:DefaultEvictEventListener.java

示例9: BulkOperationCleanupAction

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
 * Constructs an action to cleanup "affected cache regions" based on a
 * set of affected table spaces.  This differs from {@link #BulkOperationCleanupAction(SessionImplementor, Queryable[])}
 * in that here we have the affected <strong>table names</strong>.  From those
 * we deduce the entity persisters which are affected based on the defined
 * {@link EntityPersister#getQuerySpaces() table spaces}; and from there, we
 * determine the affected collection regions based on any collections
 * in which those entity persisters participate as elements/keys/etc.
 *
 * @param session The session to which this request is tied.
 * @param tableSpaces The table spaces.
 */
@SuppressWarnings({ "unchecked" })
public BulkOperationCleanupAction(SessionImplementor session, Set tableSpaces) {
	final LinkedHashSet<String> spacesList = new LinkedHashSet<String>();
	spacesList.addAll( tableSpaces );

	final SessionFactoryImplementor factory = session.getFactory();
	for ( String entityName : factory.getAllClassMetadata().keySet() ) {
		final EntityPersister persister = factory.getEntityPersister( entityName );
		final String[] entitySpaces = (String[]) persister.getQuerySpaces();
		if ( affectedEntity( tableSpaces, entitySpaces ) ) {
			spacesList.addAll( Arrays.asList( entitySpaces ) );

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

			final Set<String> roles = session.getFactory().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,代码行数:48,代码来源:BulkOperationCleanupAction.java

示例10: determinePreviousNaturalIdValues

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
private Object[] determinePreviousNaturalIdValues(
		EntityPersister persister,
		Object[] previousState,
		SessionImplementor session,
		Serializable id) {
	if ( ! persister.hasNaturalIdentifier() ) {
		return null;
	}

	if ( previousState != null ) {
		return session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( previousState, persister );
	}

	return session.getPersistenceContext().getNaturalIdSnapshot( id, persister );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:EntityUpdateAction.java

示例11: getNaturalIdSnapshot

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public Object[] getNaturalIdSnapshot(Serializable id, EntityPersister persister) throws HibernateException {
	if ( !persister.hasNaturalIdentifier() ) {
		return null;
	}

	persister = locateProperPersister( persister );

	// let's first see if it is part of the natural id cache...
	final Object[] cachedValue = naturalIdHelper.findCachedNaturalId( persister, id );
	if ( cachedValue != null ) {
		return cachedValue;
	}

	// check to see if the natural id is mutable/immutable
	if ( persister.getEntityMetamodel().hasImmutableNaturalId() ) {
		// an immutable natural-id is not retrieved during a normal database-snapshot operation...
		final Object[] dbValue = persister.getNaturalIdentifierSnapshot( id, session );
		naturalIdHelper.cacheNaturalIdCrossReferenceFromLoad(
				persister,
				id,
				dbValue
		);
		return dbValue;
	}
	else {
		// for a mutable natural there is a likelihood that the the information will already be
		// snapshot-cached.
		final int[] props = persister.getNaturalIdentifierProperties();
		final Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
		if ( entitySnapshot == NO_ROW || entitySnapshot == null ) {
			return null;
		}

		final Object[] naturalIdSnapshotSubSet = new Object[ props.length ];
		for ( int i = 0; i < props.length; i++ ) {
			naturalIdSnapshotSubSet[i] = entitySnapshot[ props[i] ];
		}
		naturalIdHelper.cacheNaturalIdCrossReferenceFromLoad(
				persister,
				id,
				naturalIdSnapshotSubSet
		);
		return naturalIdSnapshotSubSet;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:StatefulPersistenceContext.java

示例12: tryNaturalIdLoadAccess

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
 * Checks to see if the CriteriaImpl is a naturalId lookup that can be done via
 * NaturalIdLoadAccess
 *
 * @param criteria The criteria to check as a complete natural identifier lookup.
 *
 * @return A fully configured NaturalIdLoadAccess or null, if null is returned the standard CriteriaImpl execution
 *         should be performed
 */
private NaturalIdLoadAccess tryNaturalIdLoadAccess(CriteriaImpl criteria) {
	// See if the criteria lookup is by naturalId
	if ( !criteria.isLookupByNaturalKey() ) {
		return null;
	}

	final String entityName = criteria.getEntityOrClassName();
	final EntityPersister entityPersister = factory.getEntityPersister( entityName );

	// Verify the entity actually has a natural id, needed for legacy support as NaturalIdentifier criteria
	// queries did no natural id validation
	if ( !entityPersister.hasNaturalIdentifier() ) {
		return null;
	}

	// Since isLookupByNaturalKey is true there can be only one CriterionEntry and getCriterion() will
	// return an instanceof NaturalIdentifier
	final CriterionEntry criterionEntry = (CriterionEntry) criteria.iterateExpressionEntries().next();
	final NaturalIdentifier naturalIdentifier = (NaturalIdentifier) criterionEntry.getCriterion();

	final Map<String, Object> naturalIdValues = naturalIdentifier.getNaturalIdValues();
	final int[] naturalIdentifierProperties = entityPersister.getNaturalIdentifierProperties();

	// Verify the NaturalIdentifier criterion includes all naturalId properties, first check that the property counts match
	if ( naturalIdentifierProperties.length != naturalIdValues.size() ) {
		return null;
	}

	final String[] propertyNames = entityPersister.getPropertyNames();
	final NaturalIdLoadAccess naturalIdLoader = this.byNaturalId( entityName );

	// Build NaturalIdLoadAccess and in the process verify all naturalId properties were specified
	for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
		final String naturalIdProperty = propertyNames[naturalIdentifierProperties[i]];
		final Object naturalIdValue = naturalIdValues.get( naturalIdProperty );

		if ( naturalIdValue == null ) {
			// A NaturalId property is missing from the critera query, can't use NaturalIdLoadAccess
			return null;
		}

		naturalIdLoader.using( naturalIdProperty, naturalIdValue );
	}

	// Critera query contains a valid naturalId, use the new API
	LOG.warn( "Session.byNaturalId(" + entityName
			+ ") should be used for naturalId queries instead of Restrictions.naturalId() from a Criteria" );

	return naturalIdLoader;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:60,代码来源:SessionImpl.java

示例13: ResolveNaturalIdEvent

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
public ResolveNaturalIdEvent(
		Map<String, Object> naturalIdValues,
		EntityPersister entityPersister,
		LockOptions lockOptions,
		EventSource source) {
	super( source );

	if ( entityPersister == null ) {
		throw new IllegalArgumentException( "EntityPersister is required for loading" );
	}

	if ( ! entityPersister.hasNaturalIdentifier() ) {
		throw new HibernateException( "Entity did not define a natural-id" );
	}

	if ( naturalIdValues == null || naturalIdValues.isEmpty() ) {
		throw new IllegalArgumentException( "natural-id to load is required" );
	}

	if ( entityPersister.getNaturalIdentifierProperties().length != naturalIdValues.size() ) {
		throw new HibernateException(
				String.format(
					"Entity [%s] defines its natural-id with %d properties but only %d were specified",
					entityPersister.getEntityName(),
					entityPersister.getNaturalIdentifierProperties().length,
					naturalIdValues.size()
				)
		);
	}

	if ( lockOptions.getLockMode() == LockMode.WRITE ) {
		throw new IllegalArgumentException( "Invalid lock mode for loading" );
	}
	else if ( lockOptions.getLockMode() == null ) {
		lockOptions.setLockMode( DEFAULT_LOCK_MODE );
	}

	this.entityPersister = entityPersister;
	this.naturalIdValues = naturalIdValues;
	this.lockOptions = lockOptions;

	int[] naturalIdPropertyPositions = entityPersister.getNaturalIdentifierProperties();
	orderedNaturalIdValues = new Object[naturalIdPropertyPositions.length];
	int i = 0;
	for ( int position : naturalIdPropertyPositions ) {
		final String propertyName = entityPersister.getPropertyNames()[position];
		if ( ! naturalIdValues.containsKey( propertyName ) ) {
			throw new HibernateException(
					String.format( "No value specified for natural-id property %s#%s", getEntityName(), propertyName )
			);
		}
		orderedNaturalIdValues[i++] = naturalIdValues.get( entityPersister.getPropertyNames()[position] );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:55,代码来源:ResolveNaturalIdEvent.java

示例14: checkNaturalId

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
private void checkNaturalId(
		EntityPersister persister,
		EntityEntry entry,
		Object[] current,
		Object[] loaded,
		SessionImplementor session) {
	if ( persister.hasNaturalIdentifier() && entry.getStatus() != Status.READ_ONLY ) {
		if ( !persister.getEntityMetamodel().hasImmutableNaturalId() ) {
			// SHORT-CUT: if the natural id is mutable (!immutable), no need to do the below checks
			// EARLY EXIT!!!
			return;
		}

		final int[] naturalIdentifierPropertiesIndexes = persister.getNaturalIdentifierProperties();
		final Type[] propertyTypes = persister.getPropertyTypes();
		final boolean[] propertyUpdateability = persister.getPropertyUpdateability();

		final Object[] snapshot = loaded == null
				? session.getPersistenceContext().getNaturalIdSnapshot( entry.getId(), persister )
				: session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( loaded, persister );

		for ( int i = 0; i < naturalIdentifierPropertiesIndexes.length; i++ ) {
			final int naturalIdentifierPropertyIndex = naturalIdentifierPropertiesIndexes[i];
			if ( propertyUpdateability[naturalIdentifierPropertyIndex] ) {
				// if the given natural id property is updatable (mutable), there is nothing to check
				continue;
			}

			final Type propertyType = propertyTypes[naturalIdentifierPropertyIndex];
			if ( !propertyType.isEqual( current[naturalIdentifierPropertyIndex], snapshot[i] ) ) {
				throw new HibernateException(
						String.format(
								"An immutable natural identifier of entity %s was altered from %s to %s",
								persister.getEntityName(),
								propertyTypes[naturalIdentifierPropertyIndex].toLoggableString(
										snapshot[i],
										session.getFactory()
								),
								propertyTypes[naturalIdentifierPropertyIndex].toLoggableString(
										current[naturalIdentifierPropertyIndex],
										session.getFactory()
								)
						)
				);
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:DefaultFlushEntityEventListener.java

示例15: doLoad

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
 * Coordinates the efforts to load a given entity.  First, an attempt is
 * made to load the entity from the session-level cache.  If not found there,
 * an attempt is made to locate it in second-level cache.  Lastly, an
 * attempt is made to load it directly from the datasource.
 *
 * @param event The load event
 * @param persister The persister for the entity being requested for load
 * @param keyToLoad The EntityKey representing the entity to be loaded.
 * @param options The load options.
 *
 * @return The loaded entity, or null.
 */
protected Object doLoad(
		final LoadEvent event,
		final EntityPersister persister,
		final EntityKey keyToLoad,
		final LoadEventListener.LoadType options) {

	final boolean traceEnabled = LOG.isTraceEnabled();
	if ( traceEnabled ) {
		LOG.tracev(
				"Attempting to resolve: {0}",
				MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
		);
	}

	Object entity = loadFromSessionCache( event, keyToLoad, options );
	if ( entity == REMOVED_ENTITY_MARKER ) {
		LOG.debug( "Load request found matching entity in context, but it is scheduled for removal; returning null" );
		return null;
	}
	if ( entity == INCONSISTENT_RTN_CLASS_MARKER ) {
		LOG.debug(
				"Load request found matching entity in context, but the matched entity was of an inconsistent return type; returning null"
		);
		return null;
	}
	if ( entity != null ) {
		if ( traceEnabled ) {
			LOG.tracev(
					"Resolved object in session cache: {0}",
					MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
			);
		}
		return entity;
	}

	entity = loadFromSecondLevelCache( event, persister, options );
	if ( entity != null ) {
		if ( traceEnabled ) {
			LOG.tracev(
					"Resolved object in second-level cache: {0}",
					MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
			);
		}
	}
	else {
		if ( traceEnabled ) {
			LOG.tracev(
					"Object not resolved in any cache: {0}",
					MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
			);
		}
		entity = loadFromDatasource( event, persister, keyToLoad, options );
	}

	if ( entity != null && persister.hasNaturalIdentifier() ) {
		event.getSession().getPersistenceContext().getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad(
				persister,
				event.getEntityId(),
				event.getSession().getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues(
						entity,
						persister
				)
		);
	}


	return entity;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:82,代码来源:DefaultLoadEventListener.java


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