org.babyfish.jimmer.sql.cache.spi.AbstractTrackingConsumerBinder 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.spi;
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.sql.cache.CacheTracker;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
public abstract class AbstractTrackingConsumerBinder extends AbstractBinder {
private static final Logger LOGGER =
LoggerFactory.getLogger(AbstractTrackingConsumerBinder.class);
public AbstractTrackingConsumerBinder(
@Nullable ImmutableType type,
@Nullable ImmutableProp prop,
@Nullable CacheTracker tracker
) {
super(type, prop);
if (tracker != null) {
tracker.addInvalidateListener(new InvalidateListenerImpl());
tracker.addReconnectListener(new ReconnectListenerImpl());
}
}
protected abstract void invalidateAll();
private class InvalidateListenerImpl implements CacheTracker.InvalidationListener {
@SuppressWarnings("unchecked")
@Override
public void onInvalidate(CacheTracker.InvalidateEvent event) {
boolean match = event.getProp() != null ?
prop == event.getProp() :
type == event.getType() && prop == null;
if (match) {
deleteAll((Collection) event.getIds(), null);
}
}
}
private class ReconnectListenerImpl implements CacheTracker.ReconnectListener {
@Override
public void onReconnect() {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(
"Cache.DeleteAll > {}",
AbstractTrackingConsumerBinder.this.toString(true)
);
}
invalidateAll();
}
}
}