类org.hibernate.engine.spi.ActionQueue源码实例Demo

下面列出了怎么用org.hibernate.engine.spi.ActionQueue的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lams   文件: SessionImpl.java
/**
 * Used by JDK serialization...
 *
 * @param ois The input stream from which we are being read...
 *
 * @throws IOException Indicates a general IO stream exception
 * @throws ClassNotFoundException Indicates a class resolution issue
 */
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
	if ( TRACE_ENABLED ) {
		log.tracef( "Deserializing Session [%s]", getSessionIdentifier() );
	}

	ois.defaultReadObject();

	persistenceContext = StatefulPersistenceContext.deserialize( ois, this );
	actionQueue = ActionQueue.deserialize( ois, this );

	loadQueryInfluencers = (LoadQueryInfluencers) ois.readObject();

	// LoadQueryInfluencers.getEnabledFilters() tries to validate each enabled
	// filter, which will fail when called before FilterImpl.afterDeserialize( factory );
	// Instead lookup the filter by name and then call FilterImpl.afterDeserialize( factory ).
	for ( String filterName : loadQueryInfluencers.getEnabledFilterNames() ) {
		( (FilterImpl) loadQueryInfluencers.getEnabledFilter( filterName ) ).afterDeserialize( getFactory() );
	}

	initializeFromSessionOwner( null );

	this.disallowOutOfTransactionUpdateOperations = !getFactory().getSessionFactoryOptions().isAllowOutOfTransactionUpdateOperations();
	this.discardOnClose = getFactory().getSessionFactoryOptions().isReleaseResourcesOnCloseEnabled();
}
 
源代码2 项目: lams   文件: SessionImpl.java
public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
	super( factory, options );

	this.actionQueue = new ActionQueue( this );
	this.persistenceContext = new StatefulPersistenceContext( this );

	this.sessionOwner = options.getSessionOwner();
	initializeFromSessionOwner( sessionOwner );

	this.autoClear = options.shouldAutoClear();
	this.autoClose = options.shouldAutoClose();
	this.queryParametersValidationEnabled = options.isQueryParametersValidationEnabled();
	this.disallowOutOfTransactionUpdateOperations = !factory.getSessionFactoryOptions().isAllowOutOfTransactionUpdateOperations();
	this.discardOnClose = getFactory().getSessionFactoryOptions().isReleaseResourcesOnCloseEnabled();

	if ( options instanceof SharedSessionCreationOptions && ( (SharedSessionCreationOptions) options ).isTransactionCoordinatorShared() ) {
		final SharedSessionCreationOptions sharedOptions = (SharedSessionCreationOptions) options;
		if ( sharedOptions.getTransactionCompletionProcesses() != null ) {
			actionQueue.setTransactionCompletionProcesses( sharedOptions.getTransactionCompletionProcesses(), true );
		}
	}

	loadQueryInfluencers = new LoadQueryInfluencers( factory );

	if ( getFactory().getStatistics().isStatisticsEnabled() ) {
		getFactory().getStatistics().openSession();
	}

	// NOTE : pulse() already handles auto-join-ability correctly
	getTransactionCoordinator().pulse();

	setDefaultProperties();
	applyProperties();

	if ( TRACE_ENABLED ) {
		log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );
	}
}
 
@Override
public CompletionStage<Void> reactiveOnAutoFlush(AutoFlushEvent event) throws HibernateException {
	final EventSource source = event.getSession();
	final SessionEventListenerManager eventListenerManager = source.getEventListenerManager();

	eventListenerManager.partialFlushStart();
	CompletionStage<Void> autoFlushStage = CompletionStages.nullFuture();
	if ( flushMightBeNeeded( source ) ) {
		// Need to get the number of collection removals before flushing to executions
		// (because flushing to executions can add collection removal actions to the action queue).
		final ActionQueue actionQueue = source.getActionQueue();
		final int oldSize = actionQueue.numberOfCollectionRemovals();

		autoFlushStage = flushEverythingToExecutions( event )
				.thenCompose( v -> {
					if ( flushIsReallyNeeded( event, source ) ) {
						LOG.trace( "Need to execute flush" );
						event.setFlushRequired( true );

						return performExecutions( source )
								.thenRun( () -> postFlush( source ) )
								.thenRun( () -> postPostFlush( source ) )
								.thenRun( () -> {
									final StatisticsImplementor statistics = source.getFactory().getStatistics();
									if ( statistics.isStatisticsEnabled() ) {
										statistics.flush();
									}
								} );

					}
					else {
						LOG.trace( "Don't need to execute flush" );
						event.setFlushRequired( false );
						actionQueue.clearFromFlushNeededCheck( oldSize );
						return CompletionStages.nullFuture();
					}
				} );
	}
	autoFlushStage.whenComplete( (v, x) -> {
		source.getEventListenerManager().flushEnd( event.getNumberOfEntitiesProcessed(), event.getNumberOfCollectionsProcessed() );
		CompletionStages.returnNullorRethrow( x );
	} );

	return autoFlushStage;
}
 
/**
 * process any unreferenced collections and then inspect all known collections,
 * scheduling creates/removes/updates
 */
private int flushCollections(final EventSource session, final PersistenceContext persistenceContext) throws HibernateException {
	LOG.trace( "Processing unreferenced collections" );

	final int count = persistenceContext.getCollectionEntriesSize();

	persistenceContext.forEachCollectionEntry(
			(persistentCollection, collectionEntry) -> {
				if ( !collectionEntry.isReached() && !collectionEntry.isIgnore() ) {
					Collections.processUnreachableCollection( persistentCollection, session );
				}
			}, true );

	// Schedule updates to collections:

	LOG.trace( "Scheduling collection removes/(re)creates/updates" );

	final ActionQueue actionQueue = session.getActionQueue();
	final Interceptor interceptor = session.getInterceptor();
	persistenceContext.forEachCollectionEntry(
			(coll, ce) -> {
				if ( ce.isDorecreate() ) {
					interceptor.onCollectionRecreate( coll, ce.getCurrentKey() );
					actionQueue.addAction(
							new CollectionRecreateAction(
									coll,
									ce.getCurrentPersister(),
									ce.getCurrentKey(),
									session
							)
					);
				}
				if ( ce.isDoremove() ) {
					interceptor.onCollectionRemove( coll, ce.getLoadedKey() );
					actionQueue.addAction(
							new CollectionRemoveAction(
									coll,
									ce.getLoadedPersister(),
									ce.getLoadedKey(),
									ce.isSnapshotEmpty( coll ),
									session
							)
					);
				}
				if ( ce.isDoupdate() ) {
					interceptor.onCollectionUpdate( coll, ce.getLoadedKey() );
					actionQueue.addAction(
							new CollectionUpdateAction(
									coll,
									ce.getLoadedPersister(),
									ce.getLoadedKey(),
									ce.isSnapshotEmpty( coll ),
									session
							)
					);
				}
				// todo : I'm not sure the !wasInitialized part should really be part of this check
				if ( !coll.wasInitialized() && coll.hasQueuedOperations() ) {
					actionQueue.addAction(
							new QueuedOperationCollectionAction(
									coll,
									ce.getLoadedPersister(),
									ce.getLoadedKey(),
									session
							)
					);
				}
			}, true );

	actionQueue.sortCollectionActions();

	return count;
}
 
源代码5 项目: lams   文件: SessionImpl.java
@Override
	public ActionQueue getActionQueue() {
		checkOpenOrWaitingForAutoClose();
//		checkTransactionSynchStatus();
		return actionQueue;
	}
 
源代码6 项目: lams   文件: SessionImpl.java
@Override
public ActionQueue.TransactionCompletionProcesses getTransactionCompletionProcesses() {
	return shareTransactionContext ?
			session.getActionQueue().getTransactionCompletionProcesses() :
			null;
}
 
源代码7 项目: gorm-hibernate5   文件: ClosureEventListener.java
public ClosureEventListener(PersistentEntity persistentEntity, boolean failOnError, List failOnErrorPackages) {
    this.persistentEntity = persistentEntity;
    Class domainClazz = persistentEntity.getJavaClass();
    this.domainMetaClass = GroovySystem.getMetaClassRegistry().getMetaClass(domainClazz);
    this.isMultiTenant = ClassUtils.isMultiTenant(domainClazz);
    saveOrUpdateCaller = buildCaller(AbstractPersistenceEvent.ONLOAD_SAVE, domainClazz);
    beforeInsertCaller = buildCaller(AbstractPersistenceEvent.BEFORE_INSERT_EVENT, domainClazz);
    EventTriggerCaller preLoadEventCaller = buildCaller(AbstractPersistenceEvent.ONLOAD_EVENT, domainClazz);
    if (preLoadEventCaller  == null) {
        this.preLoadEventCaller = buildCaller(AbstractPersistenceEvent.BEFORE_LOAD_EVENT, domainClazz);
    }
    else {
        this.preLoadEventCaller = preLoadEventCaller;
    }

    postLoadEventListener = buildCaller(AbstractPersistenceEvent.AFTER_LOAD_EVENT, domainClazz);
    postInsertEventListener = buildCaller(AbstractPersistenceEvent.AFTER_INSERT_EVENT, domainClazz);
    postUpdateEventListener = buildCaller(AbstractPersistenceEvent.AFTER_UPDATE_EVENT, domainClazz);
    postDeleteEventListener = buildCaller(AbstractPersistenceEvent.AFTER_DELETE_EVENT, domainClazz);
    preDeleteEventListener = buildCaller(AbstractPersistenceEvent.BEFORE_DELETE_EVENT, domainClazz);
    preUpdateEventListener = buildCaller(AbstractPersistenceEvent.BEFORE_UPDATE_EVENT, domainClazz);

    beforeValidateEventListener = new BeforeValidateEventTriggerCaller(domainClazz, domainMetaClass);

    if (failOnErrorPackages.size() > 0) {
        failOnErrorEnabled = ClassUtils.isClassBelowPackage(domainClazz, failOnErrorPackages);
    } else {
        failOnErrorEnabled = failOnError;
    }

    validateParams = new HashMap();
    validateParams.put(AbstractHibernateGormValidationApi.ARGUMENT_DEEP_VALIDATE, Boolean.FALSE);

    try {
        actionQueueUpdatesField=ReflectionUtils.findField(ActionQueue.class, "updates");
        actionQueueUpdatesField.setAccessible(true);
        entityUpdateActionStateField=ReflectionUtils.findField(EntityUpdateAction.class, "state");
        entityUpdateActionStateField.setAccessible(true);
    } catch (Exception e) {
        // ignore
    }
}
 
源代码8 项目: lams   文件: EventSource.java
/**
 * Get the ActionQueue for this session
 */
ActionQueue getActionQueue();
 
源代码9 项目: lams   文件: SharedSessionCreationOptions.java
ActionQueue.TransactionCompletionProcesses getTransactionCompletionProcesses(); 
 类所在包
 同包方法