diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/NoCachingTransactionSynchronizationImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/NoCachingTransactionSynchronizationImpl.java index 3e24e19c9b..e71a1a3cf6 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/NoCachingTransactionSynchronizationImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/NoCachingTransactionSynchronizationImpl.java @@ -18,6 +18,11 @@ public class NoCachingTransactionSynchronizationImpl implements CacheTransaction } + @Override + public long getCurrentTransactionStartTimestamp() { + return getCachingTimestamp(); + } + @Override public long getCachingTimestamp() { throw new UnsupportedOperationException("Method not supported when 2LC is not enabled"); diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/AbstractCacheTransactionSynchronization.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/AbstractCacheTransactionSynchronization.java index 49c11d29bd..11db5e0fcc 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/AbstractCacheTransactionSynchronization.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/AbstractCacheTransactionSynchronization.java @@ -20,6 +20,12 @@ public abstract class AbstractCacheTransactionSynchronization implements CacheTr this.regionFactory = regionFactory; } + @Override + @Deprecated(forRemoval = true) + public long getCurrentTransactionStartTimestamp() { + return lastTransactionCompletionTimestamp; + } + @Override public long getCachingTimestamp() { return lastTransactionCompletionTimestamp; diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheTransactionSynchronization.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheTransactionSynchronization.java index 7f83994e1d..0e5dfad278 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheTransactionSynchronization.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/CacheTransactionSynchronization.java @@ -38,6 +38,24 @@ package org.hibernate.cache.spi; * @author Radim Vansa */ public interface CacheTransactionSynchronization { + + /** + * What is the start time of this context object? + * + * @apiNote If not currently joined to a transaction, the timestamp from + * the last transaction is safe to use. If not ever/yet joined to a + * transaction, a timestamp at the time the Session/CacheTransactionSynchronization + * were created should be returned. + * + * @implSpec This "timestamp" need not be related to timestamp in the Java + * Date/millisecond sense. It just needs to be an incrementing value. + * + * @deprecated Use {@link CacheTransactionSynchronization#getCachingTimestamp()} instead. + * Please do implement also getCachingTimestamp, as its default implementation will be removed. + */ + @Deprecated(forRemoval = true) + long getCurrentTransactionStartTimestamp(); + /** * What is the start time of this context object? * @@ -51,7 +69,9 @@ public interface CacheTransactionSynchronization { * * An UnsupportedOperationException is thrown if 2LC has not enabled */ - long getCachingTimestamp(); + default long getCachingTimestamp() { + return getCurrentTransactionStartTimestamp(); + } /** * Callback that owning Session has become joined to a resource transaction. diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index d13ca22417..33e415154a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -258,6 +258,12 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { delegate.markForRollbackOnly(); } + @Override + @Deprecated(forRemoval = true) + public long getTransactionStartTimestamp() { + return delegate.getTransactionStartTimestamp(); + } + @Override public FlushModeType getFlushMode() { return delegate.getFlushMode(); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java index 418f93407a..7541a2e1e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java @@ -208,6 +208,18 @@ public interface SharedSessionContractImplementor */ void markForRollbackOnly(); + /** + * A "timestamp" at or before the start of the current transaction. + * + * @apiNote This "timestamp" need not be related to timestamp in the Java Date/millisecond + * sense. It just needs to be an incrementing value. See + * {@link CacheTransactionSynchronization#getCurrentTransactionStartTimestamp()} + * + * @deprecated no longer supported, will be removed soon. + */ + @Deprecated(forRemoval = true) + long getTransactionStartTimestamp(); + /** * The current {@link CacheTransactionSynchronization} associated * with this session. This may be {@code null} if the session is not diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java index 17a444e8d4..7fdddb1082 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionDelegatorBaseImpl.java @@ -364,6 +364,11 @@ public class SharedSessionDelegatorBaseImpl implements SharedSessionContractImpl delegate.markForRollbackOnly(); } + @Override + public long getTransactionStartTimestamp() { + return delegate.getTransactionStartTimestamp(); + } + @Override public CacheTransactionSynchronization getCacheTransactionSynchronization() { return delegate.getCacheTransactionSynchronization(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index a697efcc32..f20bab9c6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -513,6 +513,15 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont return cacheTransactionSync; } + /** + * @deprecated This will be removed. + */ + @Override + @Deprecated(forRemoval = true) + public long getTransactionStartTimestamp() { + return getCacheTransactionSynchronization().getCachingTimestamp(); + } + @Override public Transaction beginTransaction() { checkOpen();