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


Java EntityPersister.getNaturalIdentifierProperties方法代码示例

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


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

示例1: CachedNaturalId

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
public CachedNaturalId(EntityPersister persister, Object[] values) {
	this.persister = persister;
	this.values = values;

	final int prime = 31;
	int hashCodeCalculation = 1;
	hashCodeCalculation = prime * hashCodeCalculation + persister.hashCode();

	final int[] naturalIdPropertyIndexes = persister.getNaturalIdentifierProperties();
	naturalIdTypes = new Type[ naturalIdPropertyIndexes.length ];
	int i = 0;
	for ( int naturalIdPropertyIndex : naturalIdPropertyIndexes ) {
		final Type type = persister.getPropertyType( persister.getPropertyNames()[ naturalIdPropertyIndex ] );
		naturalIdTypes[i] = type;
		final int elementHashCode = values[i] == null ? 0 :type.getHashCode( values[i], persister.getFactory() );
		hashCodeCalculation = prime * hashCodeCalculation + elementHashCode;
		i++;
	}

	this.hashCode = hashCodeCalculation;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:NaturalIdXrefDelegate.java

示例2: extractNaturalIdValues

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public Object[] extractNaturalIdValues(Object entity, EntityPersister persister) {
	if ( entity == null ) {
		throw new AssertionFailure( "Entity from which to extract natural id value(s) cannot be null" );
	}
	if ( persister == null ) {
		throw new AssertionFailure( "Persister to use in extracting natural id value(s) cannot be null" );
	}

	final int[] naturalIdentifierProperties = persister.getNaturalIdentifierProperties();
	final Object[] naturalIdValues = new Object[naturalIdentifierProperties.length];

	for ( int i = 0; i < naturalIdentifierProperties.length; i++ ) {
		naturalIdValues[i] = persister.getPropertyValue( entity, naturalIdentifierProperties[i] );
	}

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

示例3: NaturalIdResolutionCache

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

	final int[] naturalIdPropertyIndexes = persister.getNaturalIdentifierProperties();
	naturalIdTypes = new Type[ naturalIdPropertyIndexes.length ];
	int i = 0;
	for ( int naturalIdPropertyIndex : naturalIdPropertyIndexes ) {
		naturalIdTypes[i++] = persister.getPropertyType( persister.getPropertyNames()[ naturalIdPropertyIndex ] );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:NaturalIdXrefDelegate.java

示例4: getNaturalIdValues

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
private Object[] getNaturalIdValues(Object[] state, EntityPersister persister) {
	final int[] naturalIdPropertyIndexes = persister.getNaturalIdentifierProperties();
	final Object[] naturalIdValues = new Object[naturalIdPropertyIndexes.length];

	for ( int i = 0; i < naturalIdPropertyIndexes.length; i++ ) {
		naturalIdValues[i] = state[naturalIdPropertyIndexes[i]];
	}

	return naturalIdValues;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:StatefulPersistenceContext.java

示例5: SimpleNaturalIdLoadAccessImpl

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

	if ( entityPersister.getNaturalIdentifierProperties().length != 1 ) {
		throw new HibernateException(
				String.format( "Entity [%s] did not define a simple natural id", entityPersister.getEntityName() )
		);
	}

	final int naturalIdAttributePosition = entityPersister.getNaturalIdentifierProperties()[0];
	this.naturalIdAttributeName = entityPersister.getPropertyNames()[ naturalIdAttributePosition ];
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:SessionImpl.java

示例6: NaturalIdCacheKey

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
 * Construct a new key for a caching natural identifier resolutions into the second level cache.
 * Note that an entity name should always be the root entity name, not a subclass entity name.
 *
 * @param naturalIdValues The naturalIdValues associated with the cached data
 * @param persister The persister for the entity
 * @param session The originating session
 */
public NaturalIdCacheKey(
		final Object[] naturalIdValues,
		final EntityPersister persister,
		final SessionImplementor session) {

	this.entityName = persister.getRootEntityName();
	this.tenantId = session.getTenantIdentifier();

	this.naturalIdValues = new Serializable[naturalIdValues.length];

	final SessionFactoryImplementor factory = session.getFactory();
	final int[] naturalIdPropertyIndexes = persister.getNaturalIdentifierProperties();
	final Type[] propertyTypes = persister.getPropertyTypes();

	final int prime = 31;
	int result = 1;
	result = prime * result + ( ( this.entityName == null ) ? 0 : this.entityName.hashCode() );
	result = prime * result + ( ( this.tenantId == null ) ? 0 : this.tenantId.hashCode() );
	for ( int i = 0; i < naturalIdValues.length; i++ ) {
		final int naturalIdPropertyIndex = naturalIdPropertyIndexes[i];
		final Type type = propertyTypes[naturalIdPropertyIndex];
		final Object value = naturalIdValues[i];

		result = prime * result + (value != null ? type.getHashCode( value, factory ) : 0);

		// The natural id may not be fully resolved in some situations.  See HHH-7513 for one of them
		// (re-attaching a mutable natural id uses a database snapshot and hydration does not resolve associations).
		// TODO: The snapshot should probably be revisited at some point.  Consider semi-resolving, hydrating, etc.
		if (type instanceof EntityType && type.getSemiResolvedType( factory ).getReturnedClass().isInstance( value )) {
			this.naturalIdValues[i] = (Serializable) value;
		}
		else {
			this.naturalIdValues[i] = type.disassemble( value, session, null );
		}
	}

	this.hashCode = result;
	initTransients();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:NaturalIdCacheKey.java

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: validateNaturalId

import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
 * Invariant validate of the natural id.  Checks include<ul>
 *     <li>that the entity defines a natural id</li>
 *     <li>the number of natural id values matches the expected number</li>
 * </ul>
 *
 * @param persister The persister representing the entity type.
 * @param naturalIdValues The natural id values
 */
protected void validateNaturalId(EntityPersister persister, Object[] naturalIdValues) {
	if ( !persister.hasNaturalIdentifier() ) {
		throw new IllegalArgumentException( "Entity did not define a natrual-id" );
	}
	if ( persister.getNaturalIdentifierProperties().length != naturalIdValues.length ) {
		throw new IllegalArgumentException( "Mismatch between expected number of natural-id values and found." );
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:NaturalIdXrefDelegate.java


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