Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
*/
Object getTenantIdentifierValue();

/**
* Get the current {@linkplain CacheMode cache mode} for this session.
*
* @return the current cache mode
*/
CacheMode getCacheMode();

/**
* Set the current {@linkplain CacheMode cache mode} for this session.
* <p>
* The cache mode determines the manner in which this session can interact with
* the second level cache.
*
* @param cacheMode the new cache mode
*/
void setCacheMode(CacheMode cacheMode);

/**
* End the session by releasing the JDBC connection and cleaning up.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* A stateless session comes some with designed-in limitations:
* <ul>
* <li>it does not have a first-level cache,
* <li>nor interact with any second-level cache,
* <li>nor does it implement transactional write-behind or automatic dirty
* checking.
* </ul>
Expand Down Expand Up @@ -69,6 +68,13 @@
* thus undermining the synchronous nature of operations performed through a
* stateless session. A preferred approach is to explicitly batch operations via
* {@link #insertMultiple}, {@link #updateMultiple}, or {@link #deleteMultiple}.
* <p>
* Since version 7, a stateless session makes use of the second-level cache by
* default. To bypass the second-level cache, call {@link #setCacheMode(CacheMode)},
* passing {@link CacheMode#IGNORE}, or set the configuration properties
* {@value org.hibernate.cfg.CacheSettings#JAKARTA_SHARED_CACHE_RETRIEVE_MODE}
* and {@value org.hibernate.cfg.CacheSettings#JAKARTA_SHARED_CACHE_STORE_MODE}
* to {@code BYPASS}.
*
* @author Gavin King
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.FastSessionServices;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.pretty.MessageHelper;

import static org.hibernate.internal.util.StringHelper.unqualify;
import static org.hibernate.pretty.MessageHelper.infoString;

/**
* Any action relating to insert/update/delete of a collection
Expand Down Expand Up @@ -61,14 +62,14 @@ public void afterDeserialize(EventSource session) {
// guard against NullPointerException
if ( session != null ) {
this.session = session;
this.persister = session.getFactory().getRuntimeMetamodels().getMappingMetamodel().getCollectionDescriptor( collectionRole );
this.persister = session.getFactory().getMappingMetamodel().getCollectionDescriptor( collectionRole );
}
}

@Override
public final void beforeExecutions() throws CacheException {
// we need to obtain the lock before any actions are executed, since this may be an inverse="true"
// bidirectional association and it is one of the earlier entity actions which actually updates
// bidirectional association, and it is one of the earlier entity actions which actually updates
// the database (this action is responsible for second-level cache invalidation only)
if ( persister.hasCache() ) {
final CollectionDataAccess cache = persister.getCacheAccessStrategy();
Expand Down Expand Up @@ -147,7 +148,7 @@ protected final void evict() throws CacheException {

@Override
public String toString() {
return StringHelper.unqualify( getClass().getName() ) + MessageHelper.infoString( collectionRole, key );
return unqualify( getClass().getName() ) + infoString( collectionRole, key );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.event.spi.EventSource;
import org.hibernate.internal.FastSessionServices;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;

import static org.hibernate.internal.util.StringHelper.unqualify;
import static org.hibernate.pretty.MessageHelper.infoString;

/**
* Base class for actions relating to insert/update/delete of an entity
Expand Down Expand Up @@ -101,7 +102,7 @@ public final Object getId() {
}

public final DelayedPostInsertIdentifier getDelayedId() {
return id instanceof DelayedPostInsertIdentifier ? (DelayedPostInsertIdentifier) id : null;
return id instanceof DelayedPostInsertIdentifier identifier ? identifier : null;
}

/**
Expand Down Expand Up @@ -143,7 +144,7 @@ public void beforeExecutions() {

@Override
public String toString() {
return StringHelper.unqualify( getClass().getName() ) + MessageHelper.infoString( entityName, id );
return unqualify( getClass().getName() ) + infoString( entityName, id );
}

@Override
Expand Down Expand Up @@ -185,8 +186,8 @@ public void afterDeserialize(EventSource session) {
}
}

protected EventSource eventSource() {
return getSession();
protected final EventSource eventSource() {
return session;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,7 @@ protected void postDelete() {
}

PostDeleteEvent newPostDeleteEvent() {
return new PostDeleteEvent(
getInstance(),
getId(),
state,
getPersister(),
eventSource()
);
return new PostDeleteEvent( getInstance(), getId(), state, getPersister(), eventSource() );
}

protected void postCommitDelete(boolean success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import static org.hibernate.internal.util.NullnessUtil.castNonNull;

/**
* The action for performing entity insertions when entity is using IDENTITY column identifier generation
* The action for performing entity insertions when entity is using {@code IDENTITY} column identifier generation
*
* @see EntityInsertAction
*/
Expand Down Expand Up @@ -160,21 +160,15 @@ public void doAfterTransactionCompletion(boolean success, SharedSessionContractI

protected void postInsert() {
if ( isDelayed ) {
eventSource().getPersistenceContextInternal()
getSession().getPersistenceContextInternal()
.replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId );
}
getFastSessionServices().eventListenerGroup_POST_INSERT
.fireLazyEventOnEachListener( this::newPostInsertEvent, PostInsertEventListener::onPostInsert );
}

PostInsertEvent newPostInsertEvent() {
return new PostInsertEvent(
getInstance(),
generatedId,
getState(),
getPersister(),
eventSource()
);
return new PostInsertEvent( getInstance(), generatedId, getState(), getPersister(), eventSource() );
}

protected void postCommitInsert(boolean success) {
Expand All @@ -184,8 +178,8 @@ protected void postCommitInsert(boolean success) {
}

private void postCommitInsertOnFailure(PostInsertEventListener listener, PostInsertEvent event) {
if ( listener instanceof PostCommitInsertEventListener ) {
((PostCommitInsertEventListener) listener).onPostInsertCommitFailed( event );
if ( listener instanceof PostCommitInsertEventListener postCommitInsertEventListener ) {
postCommitInsertEventListener.onPostInsertCommitFailed( event );
}
else {
//default to the legacy implementation that always fires the event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.hibernate.stat.spi.StatisticsImplementor;

/**
* The action for performing an entity insertion, for entities not defined to use IDENTITY generation.
* The action for performing an entity insertion, for entities not defined to use {@code IDENTITY} generation.
*
* @see EntityIdentityInsertAction
*/
Expand Down Expand Up @@ -216,13 +216,7 @@ protected void postInsert() {
}

private PostInsertEvent newPostInsertEvent() {
return new PostInsertEvent(
getInstance(),
getId(),
getState(),
getPersister(),
eventSource()
);
return new PostInsertEvent( getInstance(), getId(), getState(), getPersister(), eventSource() );
}

protected void postCommitInsert(boolean success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ private void handleGeneratedProperties(EntityEntry entry, GeneratedValues genera
final Object instance = getInstance();
final Object id = getId();
// get the updated snapshot of the entity state by cloning current state;
// it is safe to copy in place, since by this time no-one else (should have)
// has a reference to the array
// it is safe to copy in place, since by this time no-one else should
// have a reference to the array
TypeHelper.deepCopy(
state,
persister.getPropertyTypes(),
Expand All @@ -264,12 +264,11 @@ private void handleGeneratedProperties(EntityEntry entry, GeneratedValues genera
session
);
if ( persister.hasUpdateGeneratedProperties() ) {
// this entity defines property generation, so process those generated
// values...
// this entity defines property generation, so process those generated values
persister.processUpdateGeneratedProperties( id, instance, state, generatedValues, session );
}
// have the entity entry doAfterTransactionCompletion post-update processing, passing it the
// update state and the new version (if one).
// have the entity entry doAfterTransactionCompletion post-update processing,
// passing it the update state and the new version (if there is one)
if ( persister.isVersionPropertyGenerated() ) {
nextVersion = getVersion( state, persister );
}
Expand Down Expand Up @@ -358,14 +357,8 @@ protected boolean preUpdate() {
return false;
}
else {
final PreUpdateEvent event = new PreUpdateEvent(
getInstance(),
getId(),
state,
previousState,
getPersister(),
eventSource()
);
final PreUpdateEvent event =
new PreUpdateEvent( getInstance(), getId(), state, previousState, getPersister(), eventSource() );
boolean veto = false;
for ( PreUpdateEventListener listener : listenerGroup.listeners() ) {
veto |= listener.onPreUpdate( event );
Expand All @@ -380,15 +373,7 @@ protected void postUpdate() {
}

private PostUpdateEvent newPostUpdateEvent() {
return new PostUpdateEvent(
getInstance(),
getId(),
state,
previousState,
dirtyFields,
getPersister(),
eventSource()
);
return new PostUpdateEvent( getInstance(), getId(), state, previousState, dirtyFields, getPersister(), eventSource() );
}

protected void postCommitUpdate(boolean success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.hibernate.engine.spi.SharedSessionContractImplementor;

/**
* Base contract for accessing the underlying cached data for a particular
* Navigable of the user's domain model in a transactionally ACID manner.
* Base contract for accessing the cached data for a particular element of
* the domain model in a transactionally ACID manner.
*
* @apiNote Note that the following methods are not considered "transactional"
* in this sense: {@link #contains}, {@link #lockRegion}, {@link #unlockRegion},
Expand All @@ -21,8 +21,8 @@
*
* @implSpec The "non-transactional" methods noted in the {@code @apiNote}
* should be implemented to ignore any locking. That is, when {@link #evict}
* is called, the item should be forcibly removed from the cache regardless of
* whether anything has locked it.
* is called, the item should be forcibly removed from the cache regardless
* of whether anything has locked it.
*
* @author Steve Ebersole
* @author Gail Badner
Expand All @@ -43,8 +43,9 @@ public interface CachedDomainDataAccess {
// Transactional

/**
* Attempt to retrieve an object from the cache. Mainly used in attempting
* to resolve entities/collections from the second level cache.
* Attempt to retrieve an object from the cache. Usually used when
* attempting to resolve an entity or collection from the second-level
* cache.
*
* @param session Current session.
* @param key The key of the item to be retrieved.
Expand All @@ -56,7 +57,7 @@ public interface CachedDomainDataAccess {
Object get(SharedSessionContractImplementor session, Object key);

/**
* Attempt to cache an object, afterQuery loading from the database.
* Attempt to cache an object, after loading it from the database.
*
* @param session Current session.
* @param key The item key
Expand All @@ -74,8 +75,8 @@ boolean putFromLoad(
Object version);

/**
* Attempt to cache an object, afterQuery loading from the database, explicitly
* specifying the minimalPut behavior.
* Attempt to cache an object, after loading from the database,
* explicitly specifying the {@code minimalPut} behavior.
*
* @param session Current session.
* @param key The item key
Expand All @@ -95,12 +96,12 @@ boolean putFromLoad(
boolean minimalPutOverride);

/**
* We are going to attempt to update/delete the keyed object. This
* method is used by "asynchronous" concurrency strategies.
* Notify before an attempt to update or delete the keyed object.
* This operation is used by "asynchronous" concurrency strategies.
* <p>
* The returned object must be passed back to {@link #unlockItem}, to release the
* lock. Concurrency strategies which do not support client-visible
* locks may silently return null.
* The returned object must be passed back to {@link #unlockItem},
* to release the lock. Concurrency strategies which do not support
* client-visible locks may silently return null.
*
* @param session Current session.
* @param key The key of the item to lock
Expand All @@ -113,9 +114,9 @@ boolean putFromLoad(
SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version);

/**
* Called when we have finished the attempted update/delete (which may or
* may not have been successful), after transaction completion. This method
* is used by "asynchronous" concurrency strategies.
* Notify that an attempt to update or delete the keyed object has
* completed, with or without success, after transaction completion.
* This operation is used by "asynchronous" concurrency strategies.
*
* @param session Current session.
* @param key The item key
Expand All @@ -126,8 +127,9 @@ boolean putFromLoad(
void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock);

/**
* Called afterQuery an item has become stale (beforeQuery the transaction completes).
* This method is used by "synchronous" concurrency strategies.
* Notify that an item has become stale, before completion of the
* transaction. This operation is used by "synchronous" concurrency
* strategies.
*
* @param session Current session.
* @param key The key of the item to remove
Expand All @@ -137,7 +139,7 @@ boolean putFromLoad(
void remove(SharedSessionContractImplementor session, Object key);

/**
* Remove all data for this accessed type
* Remove all data for this accessed type.
*
* @throws CacheException Propagated from underlying cache provider
*/
Expand Down
Loading
Loading