org.hibernate.event.spi.EventSource.getFactory()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中org.hibernate.event.spi.EventSource.getFactory()方法的一些代码示例,展示了EventSource.getFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EventSource.getFactory()方法的具体详情如下:
包路径:org.hibernate.event.spi.EventSource
类名称:EventSource
方法名:getFactory

EventSource.getFactory介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

private Iterable<PostLoadEventListener> postLoadEventListeners(EventSource session) {
  return session
      .getFactory()
      .getServiceRegistry()
      .getService( EventListenerRegistry.class )
      .getEventListenerGroup( EventType.POST_LOAD )
      .listeners();
}

代码示例来源:origin: hibernate/hibernate-orm

protected EntityPersister getPersister( final LoadEvent event ) {
  if ( event.getInstanceToLoad() != null ) {
    //the load() which takes an entity does not pass an entityName
    event.setEntityClassName( event.getInstanceToLoad().getClass().getName() );
    return event.getSession().getEntityPersister(
        null,
        event.getInstanceToLoad()
    );
  }
  else {
    return event.getSession().getFactory().getEntityPersister( event.getEntityClassName() );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public boolean onPreUpdate(PreUpdateEvent event) {
  validate(
      event.getEntity(), event.getPersister().getEntityMode(), event.getPersister(),
      event.getSession().getFactory(), GroupsPerOperation.Operation.UPDATE
  );
  return false;
}

代码示例来源:origin: hibernate/hibernate-orm

public boolean onPreInsert(PreInsertEvent event) {
  validate(
      event.getEntity(), event.getPersister().getEntityMode(), event.getPersister(),
      event.getSession().getFactory(), GroupsPerOperation.Operation.INSERT
  );
  return false;
}

代码示例来源:origin: hibernate/hibernate-orm

public boolean onPreDelete(PreDeleteEvent event) {
  validate(
      event.getEntity(), event.getPersister().getEntityMode(), event.getPersister(),
      event.getSession().getFactory(), GroupsPerOperation.Operation.DELETE
  );
  return false;
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Schedules a collection for deletion.
 *
 * @param role The persister representing the collection to be removed.
 * @param collectionKey The collection key (differs from owner-id in the case of property-refs).
 * @param source The session from which the request originated.
 *
 * @throws HibernateException
 */
void removeCollection(CollectionPersister role, Serializable collectionKey, EventSource source)
    throws HibernateException {
  if ( LOG.isTraceEnabled() ) {
    LOG.tracev(
        "Collection dereferenced while transient {0}",
        MessageHelper.collectionInfoString( role, ownerIdentifier, source.getFactory() )
    );
  }
  source.getActionQueue().addAction( new CollectionRemoveAction( owner, role, collectionKey, false, source ) );
}

代码示例来源:origin: hibernate/hibernate-orm

@SuppressWarnings({"unchecked"})
  private void entityIsDeleted(PersistEvent event, Map createCache) {
    final EventSource source = event.getSession();

    final Object entity = source.getPersistenceContext().unproxy( event.getObject() );
    final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );

    LOG.tracef(
        "un-scheduling entity deletion [%s]",
        MessageHelper.infoString(
            persister,
            persister.getIdentifier( entity, source ),
            source.getFactory()
        )
    );

    if ( createCache.put( entity, entity ) == null ) {
      justCascade( createCache, source, entity, persister );
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Performs the process of loading an entity from the configured
 * underlying datasource.
 *
 * @param event The load event
 * @param persister The persister for the entity being requested for load
 *
 * @return The object loaded from the datasource, or null if not found.
 */
protected Object loadFromDatasource(
    final LoadEvent event,
    final EntityPersister persister) {
  Object entity = persister.load(
      event.getEntityId(),
      event.getInstanceToLoad(),
      event.getLockOptions(),
      event.getSession()
  );
  if ( event.isAssociationFetch() && event.getSession().getFactory().getStatistics().isStatisticsEnabled() ) {
    event.getSession().getFactory().getStatistics().fetchEntity( event.getEntityClassName() );
  }
  return entity;
}

代码示例来源:origin: hibernate/hibernate-orm

final Iterable<FlushEntityEventListener> flushListeners = source.getFactory().getServiceRegistry()
    .getService( EventListenerRegistry.class )
    .getEventListenerGroup( EventType.FLUSH_ENTITY )

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Reattach a detached (disassociated) initialized or uninitialized
 * collection wrapper, using a snapshot carried with the collection
 * wrapper
 */
protected void reattachCollection(PersistentCollection collection, CollectionType type)
throws HibernateException {
  if ( collection.wasInitialized() ) {
    CollectionPersister collectionPersister = getSession().getFactory()
    .getCollectionPersister( type.getRole() );
    getSession().getPersistenceContext()
      .addInitializedDetachedCollection( collectionPersister, collection );
  }
  else {
    if ( !isCollectionSnapshotValid(collection) ) {
      throw new HibernateException( "could not reassociate uninitialized transient collection" );
    }
    CollectionPersister collectionPersister = getSession().getFactory()
        .getCollectionPersister( collection.getRole() );
    getSession().getPersistenceContext()
      .addUninitializedDetachedCollection( collectionPersister, collection );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public void noCascade(
    EventSource session,
    Object parent,
    EntityPersister persister,
    Type propertyType,
    int propertyIndex) {
  if ( propertyType.isEntityType() ) {
    Object child = persister.getPropertyValue( parent, propertyIndex );
    String childEntityName = ((EntityType) propertyType).getAssociatedEntityName( session.getFactory() );
    if ( child != null
        && !isInManagedState( child, session )
        && !(child instanceof HibernateProxy) //a proxy cannot be transient and it breaks ForeignKeys.isTransient
        && ForeignKeys.isTransient( childEntityName, child, null, session ) ) {
      String parentEntityName = persister.getEntityName();
      String propertyName = persister.getPropertyNames()[propertyIndex];
      throw new TransientPropertyValueException(
          "object references an unsaved transient instance - save the transient instance before flushing",
          childEntityName,
          parentEntityName,
          propertyName
      );
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

if ( source.getFactory().getStatistics().isStatisticsEnabled() ) {
  source.getFactory().getStatistics().flush();

代码示例来源:origin: hibernate/hibernate-orm

private void evictCachedCollections(Type[] types, Serializable id, EventSource source)
      throws HibernateException {
    for ( Type type : types ) {
      if ( type.isCollectionType() ) {
        CollectionPersister collectionPersister = source.getFactory().getMetamodel().collectionPersister( ( (CollectionType) type ).getRole() );
        if ( collectionPersister.hasCache() ) {
          final CollectionDataAccess cache = collectionPersister.getCacheAccessStrategy();
          final Object ck = cache.generateCacheKey(
            id,
            collectionPersister,
            source.getFactory(),
            source.getTenantIdentifier()
          );
          final SoftLock lock = cache.lockItem( source, ck, null );
          cache.remove( source, ck );
          source.getActionQueue().registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) );
        }
      }
      else if ( type.isComponentType() ) {
        CompositeType actype = (CompositeType) type;
        evictCachedCollections( actype.getSubtypes(), id, source );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-orm

/**
 * Handle the given merge event.
 *
 * @param event The merge event to be handled.
 *
 * @throws HibernateException
 */
public void onMerge(MergeEvent event) throws HibernateException {
  final EntityCopyObserver entityCopyObserver = createEntityCopyObserver( event.getSession().getFactory() );
  final MergeContext mergeContext = new MergeContext( event.getSession(), entityCopyObserver );
  try {
    onMerge( event, mergeContext );
    entityCopyObserver.topLevelMergeComplete( event.getSession() );
  }
  finally {
    entityCopyObserver.clear();
    mergeContext.clear();
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private void performReplication(
    Object entity,
    Serializable id,
    Object version,
    EntityPersister persister,
    ReplicationMode replicationMode,
    EventSource source) throws HibernateException {
  if ( LOG.isTraceEnabled() ) {
    LOG.tracev( "Replicating changes to {0}", MessageHelper.infoString( persister, id, source.getFactory() ) );
  }
  new OnReplicateVisitor( source, id, entity, true ).process( entity, persister );
  source.getPersistenceContext().addEntity(
      entity,
      ( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ),
      null,
      source.generateEntityKey( id, persister ),
      version,
      LockMode.NONE,
      true,
      persister,
      true
  );
  cascadeAfterReplicate( entity, persister, replicationMode, source );
}

代码示例来源:origin: hibernate/hibernate-orm

CollectionPersister persister = session.getFactory().getCollectionPersister( type.getRole() );

代码示例来源:origin: hibernate/hibernate-orm

private boolean isUpdateNecessary(final FlushEntityEvent event, final boolean mightBeDirty) {
  final Status status = event.getEntityEntry().getStatus();
  if ( mightBeDirty || status == Status.DELETED ) {
    // compare to cached state (ignoring collections unless versioned)
    dirtyCheck( event );
    if ( isUpdateNecessary( event ) ) {
      return true;
    }
    else {
      if ( SelfDirtinessTracker.class.isInstance( event.getEntity() ) ) {
        ( (SelfDirtinessTracker) event.getEntity() ).$$_hibernate_clearDirtyAttributes();
      }
      event.getSession()
          .getFactory()
          .getCustomEntityDirtinessStrategy()
          .resetDirty( event.getEntity(), event.getEntityEntry().getPersister(), event.getSession() );
      return false;
    }
  }
  else {
    return hasDirtyCollections( event, event.getEntityEntry().getPersister(), status );
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@SuppressWarnings( value = {"unchecked"} )
private void logFlushResults(FlushEvent event) {
  if ( !LOG.isDebugEnabled() ) {
    return;
  }
  final EventSource session = event.getSession();
  final PersistenceContext persistenceContext = session.getPersistenceContext();
  LOG.debugf(
      "Flushed: %s insertions, %s updates, %s deletions to %s objects",
      session.getActionQueue().numberOfInsertions(),
      session.getActionQueue().numberOfUpdates(),
      session.getActionQueue().numberOfDeletions(),
      persistenceContext.getNumberOfManagedEntities()
  );
  LOG.debugf(
      "Flushed: %s (re)creations, %s updates, %s removals to %s collections",
      session.getActionQueue().numberOfCollectionCreations(),
      session.getActionQueue().numberOfCollectionUpdates(),
      session.getActionQueue().numberOfCollectionRemovals(),
      persistenceContext.getCollectionEntries().size()
  );
  new EntityPrinter( session.getFactory() ).toString(
      persistenceContext.getEntitiesByKey().entrySet()
  );
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
  if ( collection == CollectionType.UNFETCHED_COLLECTION ) {
    return null;
  }
  final EventSource session = getSession();
  final CollectionPersister persister = session.getFactory().getMetamodel().collectionPersister( type.getRole() );
  if ( isUpdate ) {
    removeCollection( persister, extractCollectionKeyFromOwner( persister ), session );
  }
  if ( collection != null && collection instanceof PersistentCollection ) {
    final PersistentCollection wrapper = (PersistentCollection) collection;
    wrapper.setCurrentSession( (SessionImplementor) session );
    if ( wrapper.wasInitialized() ) {
      session.getPersistenceContext().addNewCollection( persister, wrapper );
    }
    else {
      reattachCollection( wrapper, type );
    }
  }
  else {
    // otherwise a null or brand new collection
    // this will also (inefficiently) handle arrays, which
    // have no snapshot, so we can't do any better
    //processArrayOrNewCollection(collection, type);
  }
  return null;
}

代码示例来源:origin: hibernate/hibernate-orm

LOG.tracev(
    "Loading entity: {0}",
    MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
);

相关文章