org.babyfish.jimmer.sql.TransientResolverManager 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;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.babyfish.jimmer.impl.util.GenericValidator;
import org.babyfish.jimmer.impl.util.PropCache;
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.ImmutableType;
import org.babyfish.jimmer.meta.ModelException;
import org.babyfish.jimmer.impl.util.Classes;
import org.babyfish.jimmer.meta.TargetLevel;
import org.babyfish.jimmer.sql.cache.Cache;
import org.babyfish.jimmer.sql.cache.Caches;
import org.babyfish.jimmer.sql.cache.CachesImpl;
import org.babyfish.jimmer.sql.cache.spi.PropCacheInvalidators;
import org.babyfish.jimmer.sql.event.AssociationEvent;
import org.babyfish.jimmer.sql.event.EntityEvent;
import org.babyfish.jimmer.sql.di.AopProxyProvider;
import org.babyfish.jimmer.sql.di.StrategyProvider;
import org.babyfish.jimmer.sql.di.TransientResolverProvider;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
class TransientResolverManager {
private final TransientResolverProvider transientResolverProvider;
private final AopProxyProvider aopProxyProvider;
private JSqlClient sqlClient;
private final PropCache> resolverCache =
new PropCache<>(this::createResolver, true);
TransientResolverManager(TransientResolverProvider transientResolverProvider, AopProxyProvider aopProxyProvider) {
this.transientResolverProvider = transientResolverProvider;
this.aopProxyProvider = aopProxyProvider;
}
void initialize(JSqlClient sqlClient) {
if (this.sqlClient != null) {
throw new IllegalStateException("The current object has been initialized");
}
this.sqlClient = sqlClient;
Caches caches = sqlClient.getCaches();
if (caches != null) {
// Important, initialize necessary resolvers
for (ImmutableType type : ((CachesImpl)caches).getObjectCacheMap().keySet()) {
for (ImmutableProp prop : type.getProps().values()) {
if (prop.hasTransientResolver()) {
get(prop);
}
}
}
for (ImmutableProp prop : ((CachesImpl)caches).getPropCacheMap().keySet()) {
if (prop.hasTransientResolver()) {
get(prop);
}
}
}
}
public TransientResolver, ?> get(ImmutableProp prop) {
return resolverCache.get(prop);
}
public StrategyProvider> getTransientResolverProvider() {
return transientResolverProvider;
}
private TransientResolver, ?> createResolver(ImmutableProp prop) {
TransientResolver, ?> resolver = createResolver0(prop);
if (resolver != null) {
Cache