org.hibernate.engine.spi.ActionQueue Java Examples

The following examples show how to use org.hibernate.engine.spi.ActionQueue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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() );
	}
}
 
Example #3
Source File: DefaultReactiveAutoFlushEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
@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;
}
 
Example #4
Source File: AbstractReactiveFlushingEventListener.java    From hibernate-reactive with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
	public ActionQueue getActionQueue() {
		checkOpenOrWaitingForAutoClose();
//		checkTransactionSynchStatus();
		return actionQueue;
	}
 
Example #6
Source File: SessionImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public ActionQueue.TransactionCompletionProcesses getTransactionCompletionProcesses() {
	return shareTransactionContext ?
			session.getActionQueue().getTransactionCompletionProcesses() :
			null;
}
 
Example #7
Source File: ClosureEventListener.java    From gorm-hibernate5 with Apache License 2.0 4 votes vote down vote up
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
    }
}
 
Example #8
Source File: EventSource.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the ActionQueue for this session
 */
ActionQueue getActionQueue();
 
Example #9
Source File: SharedSessionCreationOptions.java    From lams with GNU General Public License v2.0 votes vote down vote up
ActionQueue.TransactionCompletionProcesses getTransactionCompletionProcesses();