Search in sources :

Example 1 with AccessorInterceptor

use of org.redisson.liveobject.core.AccessorInterceptor in project redisson by redisson.

the class RedissonLiveObjectService method registerClassInternal.

private <T> void registerClassInternal(Class<T> entityClass) {
    DynamicType.Builder<T> builder = new ByteBuddy().subclass(entityClass);
    for (FieldDescription.InDefinedShape field : Introspectior.getTypeDescription(LiveObjectTemplate.class).getDeclaredFields()) {
        builder = builder.define(field);
    }
    Class<? extends T> proxied = builder.method(ElementMatchers.isDeclaredBy(Introspectior.getTypeDescription(RLiveObject.class)).and(ElementMatchers.isGetter().or(ElementMatchers.isSetter()).or(ElementMatchers.named("isPhantom")).or(ElementMatchers.named("delete")))).intercept(MethodDelegation.withDefaultConfiguration().withBinders(FieldProxy.Binder.install(LiveObjectInterceptor.Getter.class, LiveObjectInterceptor.Setter.class)).to(new LiveObjectInterceptor(redisson, codecProvider, entityClass, getRIdFieldName(entityClass)))).implement(RLiveObject.class).method(ElementMatchers.isAnnotatedWith(RFieldAccessor.class).and(ElementMatchers.named("get").or(ElementMatchers.named("set")))).intercept(MethodDelegation.to(FieldAccessorInterceptor.class)).method(ElementMatchers.isDeclaredBy(RObject.class).or(ElementMatchers.isDeclaredBy(RObjectAsync.class))).intercept(MethodDelegation.to(RObjectInterceptor.class)).implement(RObject.class).method(ElementMatchers.isDeclaredBy(RExpirable.class).or(ElementMatchers.isDeclaredBy(RExpirableAsync.class))).intercept(MethodDelegation.to(RExpirableInterceptor.class)).implement(RExpirable.class).method(ElementMatchers.isDeclaredBy(Map.class).or(ElementMatchers.isDeclaredBy(ConcurrentMap.class)).or(ElementMatchers.isDeclaredBy(RMapAsync.class)).or(ElementMatchers.isDeclaredBy(RMap.class))).intercept(MethodDelegation.to(RMapInterceptor.class)).implement(RMap.class).method(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class)).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RLiveObject.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RExpirable.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RExpirableAsync.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RObject.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(RObjectAsync.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(ConcurrentMap.class))).and(ElementMatchers.not(ElementMatchers.isDeclaredBy(Map.class))).and(ElementMatchers.isGetter().or(ElementMatchers.isSetter())).and(ElementMatchers.isPublic().or(ElementMatchers.isProtected()))).intercept(MethodDelegation.to(new AccessorInterceptor(redisson, objectBuilder))).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
    classCache.putIfAbsent(entityClass, proxied);
}
Also used : RObjectAsync(org.redisson.api.RObjectAsync) FieldAccessorInterceptor(org.redisson.liveobject.core.FieldAccessorInterceptor) DynamicType(net.bytebuddy.dynamic.DynamicType) ConcurrentMap(java.util.concurrent.ConcurrentMap) ByteBuddy(net.bytebuddy.ByteBuddy) LiveObjectTemplate(org.redisson.liveobject.LiveObjectTemplate) RMap(org.redisson.api.RMap) FieldDescription(net.bytebuddy.description.field.FieldDescription) RObjectInterceptor(org.redisson.liveobject.core.RObjectInterceptor) RMapInterceptor(org.redisson.liveobject.core.RMapInterceptor) RExpirableAsync(org.redisson.api.RExpirableAsync) RObject(org.redisson.api.RObject) RLiveObject(org.redisson.api.RLiveObject) RFieldAccessor(org.redisson.api.annotation.RFieldAccessor) RObject(org.redisson.api.RObject) RLiveObject(org.redisson.api.RLiveObject) LiveObjectInterceptor(org.redisson.liveobject.core.LiveObjectInterceptor) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) LinkedHashMap(java.util.LinkedHashMap) RMap(org.redisson.api.RMap) AccessorInterceptor(org.redisson.liveobject.core.AccessorInterceptor) FieldAccessorInterceptor(org.redisson.liveobject.core.FieldAccessorInterceptor)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 ByteBuddy (net.bytebuddy.ByteBuddy)1 FieldDescription (net.bytebuddy.description.field.FieldDescription)1 DynamicType (net.bytebuddy.dynamic.DynamicType)1 RExpirableAsync (org.redisson.api.RExpirableAsync)1 RLiveObject (org.redisson.api.RLiveObject)1 RMap (org.redisson.api.RMap)1 RObject (org.redisson.api.RObject)1 RObjectAsync (org.redisson.api.RObjectAsync)1 RFieldAccessor (org.redisson.api.annotation.RFieldAccessor)1 LiveObjectTemplate (org.redisson.liveobject.LiveObjectTemplate)1 AccessorInterceptor (org.redisson.liveobject.core.AccessorInterceptor)1 FieldAccessorInterceptor (org.redisson.liveobject.core.FieldAccessorInterceptor)1 LiveObjectInterceptor (org.redisson.liveobject.core.LiveObjectInterceptor)1 RMapInterceptor (org.redisson.liveobject.core.RMapInterceptor)1 RObjectInterceptor (org.redisson.liveobject.core.RObjectInterceptor)1