org.babyfish.jimmer.sql.cache.chain.LockableBinder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-sql Show documentation
Show all versions of jimmer-sql Show documentation
A revolutionary ORM framework for both java and kotlin
package org.babyfish.jimmer.sql.cache.chain;
import org.babyfish.jimmer.sql.cache.CacheLocker;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Duration;
public interface LockableBinder extends SimpleBinder {
@NotNull
String keyPrefix();
@NotNull
default SimpleBinder hardLock(
@Nullable CacheLocker cacheLocker,
@Nullable Duration leaseDuration
) {
return lock(cacheLocker, null, leaseDuration);
}
@NotNull
default SimpleBinder softLock(
@Nullable CacheLocker cacheLocker,
@Nullable Duration leaseDuration
) {
return lock(cacheLocker, Duration.ZERO, leaseDuration);
}
@NotNull
default SimpleBinder lock(
@Nullable CacheLocker cacheLocker,
@Nullable Duration waitDuration,
@Nullable Duration leaseDuration
) {
if (cacheLocker == null) {
return this;
}
if (this instanceof LockableBinder.Parameterized, ?>) {
return new ParameterizedLockedSimpleBinder<>(
(LockableBinder.Parameterized) this,
cacheLocker,
waitDuration,
leaseDuration
);
}
return new LockedSimpleBinder<>(
this,
cacheLocker,
waitDuration,
leaseDuration
);
}
interface Parameterized extends LockableBinder, SimpleBinder.Parameterized {
@NotNull
default SimpleBinder.Parameterized hardLock(
@Nullable CacheLocker cacheLocker,
@Nullable Duration leaseDuration
) {
return lock(cacheLocker, Duration.ZERO, leaseDuration);
}
@NotNull
default SimpleBinder softLock(
@Nullable CacheLocker cacheLocker,
@Nullable Duration leaseDuration
) {
return lock(cacheLocker, Duration.ZERO, leaseDuration);
}
@NotNull
default SimpleBinder.Parameterized lock(
@Nullable CacheLocker cacheLocker,
@Nullable Duration waitDuration,
@Nullable Duration leaseDuration
) {
if (cacheLocker == null) {
return this;
}
return new ParameterizedLockedSimpleBinder<>(
this,
cacheLocker,
waitDuration,
leaseDuration
);
}
}
}