本文整理汇总了Java中org.hibernate.persister.entity.EntityPersister.getEntityName方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPersister.getEntityName方法的具体用法?Java EntityPersister.getEntityName怎么用?Java EntityPersister.getEntityName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.persister.entity.EntityPersister
的用法示例。
在下文中一共展示了EntityPersister.getEntityName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: StandardCacheEntryImpl
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Constructs a StandardCacheEntryImpl
*
* @param state The extracted state
* @param persister The entity persister
* @param unfetched Are any values present in state unfetched?
* @param version The current version (if versioned)
* @param session The originating session
* @param owner The owner
*
* @throws HibernateException Generally indicates a problem performing the dis-assembly.
*/
public StandardCacheEntryImpl(
final Object[] state,
final EntityPersister persister,
final boolean unfetched,
final Object version,
final SessionImplementor session,
final Object owner)
throws HibernateException {
// disassembled state gets put in a new array (we write to cache by value!)
this.disassembledState = TypeHelper.disassemble(
state,
persister.getPropertyTypes(),
persister.isLazyPropertiesCacheable() ? null : persister.getPropertyLaziness(),
session,
owner
);
subclass = persister.getEntityName();
lazyPropertiesAreUnfetched = unfetched || !persister.isLazyPropertiesCacheable();
this.version = version;
}
示例2: checkId
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* make sure user didn't mangle the id
*/
public void checkId(Object object, EntityPersister persister, Serializable id, SessionImplementor session)
throws HibernateException {
if ( id != null && id instanceof DelayedPostInsertIdentifier ) {
// this is a situation where the entity id is assigned by a post-insert generator
// and was saved outside the transaction forcing it to be delayed
return;
}
if ( persister.canExtractIdOutOfEntity() ) {
Serializable oid = persister.getIdentifier( object, session );
if ( id == null ) {
throw new AssertionFailure( "null id in " + persister.getEntityName() + " entry (don't flush the Session after an exception occurs)" );
}
if ( !persister.getIdentifierType().isEqual( id, oid, session.getFactory() ) ) {
throw new HibernateException(
"identifier of an instance of " + persister.getEntityName() + " was altered from "
+ id + " to " + oid
);
}
}
}
示例3: getDatabaseSnapshot
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) {
if ( persister.isSelectBeforeUpdateRequired() ) {
Object[] snapshot = session.getPersistenceContext()
.getDatabaseSnapshot( id, persister );
if ( snapshot == null ) {
//do we even really need this? the update will fail anyway....
if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
session.getFactory().getStatisticsImplementor()
.optimisticFailure( persister.getEntityName() );
}
throw new StaleObjectStateException( persister.getEntityName(), id );
}
return snapshot;
}
// TODO: optimize away this lookup for entities w/o unsaved-value="undefined"
final EntityKey entityKey = session.generateEntityKey( id, persister );
return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey );
}
示例4: getUpdateId
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Determine the id to use for updating.
*
* @param entity The entity.
* @param persister The entity persister
* @param requestedId The requested identifier
* @param session The session
*
* @return The id.
*
* @throws TransientObjectException If the entity is considered transient.
*/
protected Serializable getUpdateId(
Object entity,
EntityPersister persister,
Serializable requestedId,
SessionImplementor session) {
// use the id assigned to the instance
Serializable id = persister.getIdentifier( entity, session );
if ( id == null ) {
// assume this is a newly instantiated transient object
// which should be saved rather than updated
throw new TransientObjectException(
"The given object has a null identifier: " +
persister.getEntityName()
);
}
else {
return id;
}
}
示例5: checkVersion
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
private void checkVersion(
SessionImplementor session,
ResultSet resultSet,
EntityPersister persister,
EntityAliases entityAliases,
EntityKey entityKey,
Object entityInstance) {
final Object version = session.getPersistenceContext().getEntry( entityInstance ).getVersion();
if ( version != null ) {
//null version means the object is in the process of being loaded somewhere else in the ResultSet
VersionType versionType = persister.getVersionType();
final Object currentVersion;
try {
currentVersion = versionType.nullSafeGet(
resultSet,
entityAliases.getSuffixedVersionAliases(),
session,
null
);
}
catch (SQLException e) {
throw session.getFactory().getJdbcServices().getSqlExceptionHelper().convert(
e,
"Could not read version value from result set"
);
}
if ( !versionType.isEqual( version, currentVersion ) ) {
if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
session.getFactory().getStatisticsImplementor().optimisticFailure( persister.getEntityName() );
}
throw new StaleObjectStateException( persister.getEntityName(), entityKey.getIdentifier() );
}
}
}
示例6: determineFetchStyleByProfile
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Determine the fetch-style (if one) explicitly set for this association via fetch profiles.
* <p/>
* Note that currently fetch profiles only allow specifying join fetching, so this method currently
* returns either (a) FetchStyle.JOIN or (b) null
*
* @param loadQueryInfluencers
* @param persister
* @param path
* @param propertyNumber
*
* @return
*/
public static FetchStyle determineFetchStyleByProfile(
LoadQueryInfluencers loadQueryInfluencers,
EntityPersister persister,
PropertyPath path,
int propertyNumber) {
if ( !loadQueryInfluencers.hasEnabledFetchProfiles() ) {
// perf optimization
return null;
}
// ugh, this stuff has to be made easier...
final String fullPath = path.getFullPath();
final String rootPropertyName = ( (OuterJoinLoadable) persister ).getSubclassPropertyName( propertyNumber );
int pos = fullPath.lastIndexOf( rootPropertyName );
final String relativePropertyPath = pos >= 0
? fullPath.substring( pos )
: rootPropertyName;
final String fetchRole = persister.getEntityName() + "." + relativePropertyPath;
for ( String profileName : loadQueryInfluencers.getEnabledFetchProfileNames() ) {
final FetchProfile profile = loadQueryInfluencers.getSessionFactory().getFetchProfile( profileName );
final Fetch fetch = profile.getFetchByRole( fetchRole );
if ( fetch != null && Fetch.Style.JOIN == fetch.getStyle() ) {
return FetchStyle.JOIN;
}
}
return null;
}
示例7: noCascade
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
@Override
public void noCascade(
EventSource session,
Object child,
Object parent,
EntityPersister persister,
int propertyIndex) {
if ( child == null ) {
return;
}
Type type = persister.getPropertyTypes()[propertyIndex];
if ( type.isEntityType() ) {
String childEntityName = ((EntityType) type).getAssociatedEntityName( session.getFactory() );
if ( !isInManagedState( child, session )
&& !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
&& ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
String parentEntiytName = persister.getEntityName();
String propertyName = persister.getPropertyNames()[propertyIndex];
throw new TransientPropertyValueException(
"object references an unsaved transient instance - save the transient instance before flushing",
childEntityName,
parentEntiytName,
propertyName
);
}
}
}
示例8: stashInvalidNaturalIdReference
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* As part of "load synchronization process", if a particular natural id is found to have changed we need to track
* its invalidity until after the next flush. This method lets the "load synchronization process" indicate
* when it has encountered such changes.
*
* @param persister The persister representing the entity type.
* @param invalidNaturalIdValues The "old" natural id values.
*
* @see org.hibernate.NaturalIdLoadAccess#setSynchronizationEnabled
*/
public void stashInvalidNaturalIdReference(EntityPersister persister, Object[] invalidNaturalIdValues) {
persister = locatePersisterForKey( persister );
final NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
if ( entityNaturalIdResolutionCache == null ) {
throw new AssertionFailure( "Expecting NaturalIdResolutionCache to exist already for entity " + persister.getEntityName() );
}
entityNaturalIdResolutionCache.stashInvalidNaturalIdReference( invalidNaturalIdValues );
}
示例9: onLock
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Handle the given lock event.
*
* @param event The lock event to be handled.
* @throws HibernateException
*/
public void onLock(LockEvent event) throws HibernateException {
if ( event.getObject() == null ) {
throw new NullPointerException( "attempted to lock null" );
}
if ( event.getLockMode() == LockMode.WRITE ) {
throw new HibernateException( "Invalid lock mode for lock()" );
}
if ( event.getLockMode() == LockMode.UPGRADE_SKIPLOCKED ) {
LOG.explicitSkipLockedLockCombo();
}
SessionImplementor source = event.getSession();
Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() );
//TODO: if object was an uninitialized proxy, this is inefficient,
// resulting in two SQL selects
EntityEntry entry = source.getPersistenceContext().getEntry(entity);
if (entry==null) {
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
final Serializable id = persister.getIdentifier( entity, source );
if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) {
throw new TransientObjectException(
"cannot lock an unsaved transient instance: " +
persister.getEntityName()
);
}
entry = reassociate(event, entity, id, persister);
cascadeOnLock(event, persister, entity);
}
upgradeLock( entity, entry, event.getLockOptions(), event.getSession() );
}
示例10: checkNullability
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Check nullability of the class persister properties
*
* @param values entity properties
* @param persister class persister
* @param isUpdate whether it is intended to be updated or saved
*
* @throws PropertyValueException Break the nullability of one property
* @throws HibernateException error while getting Component values
*/
public void checkNullability(
final Object[] values,
final EntityPersister persister,
final boolean isUpdate) throws HibernateException {
/*
* Typically when Bean Validation is on, we don't want to validate null values
* at the Hibernate Core level. Hence the checkNullability setting.
*/
if ( checkNullability ) {
/*
* Algorithm
* Check for any level one nullability breaks
* Look at non null components to
* recursively check next level of nullability breaks
* Look at Collections contraining component to
* recursively check next level of nullability breaks
*
*
* In the previous implementation, not-null stuffs where checked
* filtering by level one only updateable
* or insertable columns. So setting a sub component as update="false"
* has no effect on not-null check if the main component had good checkeability
* In this implementation, we keep this feature.
* However, I never see any documentation mentioning that, but it's for
* sure a limitation.
*/
final boolean[] nullability = persister.getPropertyNullability();
final boolean[] checkability = isUpdate ?
persister.getPropertyUpdateability() :
persister.getPropertyInsertability();
final Type[] propertyTypes = persister.getPropertyTypes();
for ( int i = 0; i < values.length; i++ ) {
if ( checkability[i] && values[i]!= LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
final Object value = values[i];
if ( !nullability[i] && value == null ) {
//check basic level one nullablilty
throw new PropertyValueException(
"not-null property references a null or transient value",
persister.getEntityName(),
persister.getPropertyNames()[i]
);
}
else if ( value != null ) {
//values is not null and is checkable, we'll look deeper
final String breakProperties = checkSubElementsNullability( propertyTypes[i], value );
if ( breakProperties != null ) {
throw new PropertyValueException(
"not-null property references a null or transient value",
persister.getEntityName(),
buildPropertyPath( persister.getPropertyNames()[i], breakProperties )
);
}
}
}
}
}
}
示例11: 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;
}
示例12: entityIsDetached
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
protected void entityIsDetached(MergeEvent event, Map copyCache) {
LOG.trace( "Merging detached instance" );
final Object entity = event.getEntity();
final EventSource source = event.getSession();
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
final String entityName = persister.getEntityName();
Serializable id = event.getRequestedId();
if ( id == null ) {
id = persister.getIdentifier( entity, source );
}
else {
// check that entity id = requestedId
Serializable entityId = persister.getIdentifier( entity, source );
if ( !persister.getIdentifierType().isEqual( id, entityId, source.getFactory() ) ) {
throw new HibernateException( "merge requested with id not matching id of passed entity" );
}
}
String previousFetchProfile = source.getFetchProfile();
source.setFetchProfile( "merge" );
//we must clone embedded composite identifiers, or
//we will get back the same instance that we pass in
final Serializable clonedIdentifier = (Serializable) persister.getIdentifierType()
.deepCopy( id, source.getFactory() );
final Object result = source.get( entityName, clonedIdentifier );
source.setFetchProfile( previousFetchProfile );
if ( result == null ) {
//TODO: we should throw an exception if we really *know* for sure
// that this is a detached instance, rather than just assuming
//throw new StaleObjectStateException(entityName, id);
// we got here because we assumed that an instance
// with an assigned id was detached, when it was
// really persistent
entityIsTransient( event, copyCache );
}
else {
( (MergeContext) copyCache ).put( entity, result, true ); //before cascade!
final Object target = source.getPersistenceContext().unproxy( result );
if ( target == entity ) {
throw new AssertionFailure( "entity was not detached" );
}
else if ( !source.getEntityName( target ).equals( entityName ) ) {
throw new WrongClassException(
"class of the given object did not match class of persistent copy",
event.getRequestedId(),
entityName
);
}
else if ( isVersionChanged( entity, source, persister, target ) ) {
if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
source.getFactory().getStatisticsImplementor()
.optimisticFailure( entityName );
}
throw new StaleObjectStateException( entityName, id );
}
// cascade first, so that all unsaved objects get their
// copy created before we actually copy
cascadeOnMerge( source, persister, entity, copyCache );
copyValues( persister, entity, target, source, copyCache );
//copyValues works by reflection, so explicitly mark the entity instance dirty
markInterceptorDirty( entity, target, persister );
event.setResult( result );
}
}
示例13: performSave
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Prepares the save call by checking the session caches for a pre-existing
* entity and performing any lifecycle callbacks.
*
* @param entity The entity to be saved.
* @param id The id by which to save the entity.
* @param persister The entity's persister instance.
* @param useIdentityColumn Is an identity column being used?
* @param anything Generally cascade-specific information.
* @param source The session from which the event originated.
* @param requiresImmediateIdAccess does the event context require
* access to the identifier immediately after execution of this method (if
* not, post-insert style id generators may be postponed if we are outside
* a transaction).
*
* @return The id used to save the entity; may be null depending on the
* type of id generator used and the requiresImmediateIdAccess value
*/
protected Serializable performSave(
Object entity,
Serializable id,
EntityPersister persister,
boolean useIdentityColumn,
Object anything,
EventSource source,
boolean requiresImmediateIdAccess) {
if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Saving {0}", MessageHelper.infoString( persister, id, source.getFactory() ) );
}
final EntityKey key;
if ( !useIdentityColumn ) {
key = source.generateEntityKey( id, persister );
Object old = source.getPersistenceContext().getEntity( key );
if ( old != null ) {
if ( source.getPersistenceContext().getEntry( old ).getStatus() == Status.DELETED ) {
source.forceFlush( source.getPersistenceContext().getEntry( old ) );
}
else {
throw new NonUniqueObjectException( id, persister.getEntityName() );
}
}
persister.setIdentifier( entity, id, source );
}
else {
key = null;
}
if ( invokeSaveLifecycle( entity, persister, source ) ) {
return id; //EARLY EXIT
}
return performSaveOrReplicate(
entity,
key,
persister,
useIdentityColumn,
anything,
source,
requiresImmediateIdAccess
);
}
示例14: createElementJoin
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
FromElement createElementJoin(QueryableCollection queryableCollection) throws SemanticException {
FromElement elem;
implied = true; //TODO: always true for now, but not if we later decide to support elements() in the from clause
inElementsFunction = true;
Type elementType = queryableCollection.getElementType();
if ( !elementType.isEntityType() ) {
throw new IllegalArgumentException( "Cannot create element join for a collection of non-entities!" );
}
this.queryableCollection = queryableCollection;
SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
FromElement destination = null;
String tableAlias = null;
EntityPersister entityPersister = queryableCollection.getElementPersister();
tableAlias = fromClause.getAliasGenerator().createName( entityPersister.getEntityName() );
String associatedEntityName = entityPersister.getEntityName();
EntityPersister targetEntityPersister = sfh.requireClassPersister( associatedEntityName );
// Create the FROM element for the target (the elements of the collection).
destination = createAndAddFromElement(
associatedEntityName,
classAlias,
targetEntityPersister,
(EntityType) queryableCollection.getElementType(),
tableAlias
);
// If the join is implied, then don't include sub-classes on the element.
if ( implied ) {
destination.setIncludeSubclasses( false );
}
fromClause.addCollectionJoinFromElementByPath( path, destination );
// origin.addDestination(destination);
// Add the query spaces.
fromClause.getWalker().addQuerySpaces( entityPersister.getQuerySpaces() );
CollectionType type = queryableCollection.getCollectionType();
String role = type.getRole();
String roleAlias = origin.getTableAlias();
String[] targetColumns = sfh.getCollectionElementColumns( role, roleAlias );
AssociationType elementAssociationType = sfh.getElementAssociationType( type );
// Create the join element under the from element.
JoinType joinType = JoinType.INNER_JOIN;
JoinSequence joinSequence = sfh.createJoinSequence(
implied,
elementAssociationType,
tableAlias,
joinType,
targetColumns
);
elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
elem.setUseFromFragment( true ); // The associated entity is implied, but it must be included in the FROM.
elem.setCollectionTableAlias( roleAlias ); // The collection alias is the role.
return elem;
}
示例15: EntityAction
import org.hibernate.persister.entity.EntityPersister; //导入方法依赖的package包/类
/**
* Instantiate an action.
*
* @param session The session from which this action is coming.
* @param id The id of the entity
* @param instance The entity instance
* @param persister The entity persister
*/
protected EntityAction(SessionImplementor session, Serializable id, Object instance, EntityPersister persister) {
this.entityName = persister.getEntityName();
this.id = id;
this.instance = instance;
this.session = session;
this.persister = persister;
}