@ -69,18 +69,18 @@ import org.redisson.liveobject.resolver.NamingScheme;
* /
public class RedissonObjectBuilder {
private static final Map < Class < ? > , Class < ? extends RObject > > supportedClassMapping = new LinkedHashMap < Class < ? > , Class < ? extends RObject > > ( ) ;
private static final Map < Class < ? > , Class < ? extends RObject > > SUPPORTED_CLASS_MAPPING = new LinkedHashMap < > ( ) ;
static {
supportedClassMapping . put ( SortedSet . class , RedissonSortedSet . class ) ;
supportedClassMapping . put ( Set . class , RedissonSet . class ) ;
supportedClassMapping . put ( ConcurrentMap . class , RedissonMap . class ) ;
supportedClassMapping . put ( Map . class , RedissonMap . class ) ;
supportedClassMapping . put ( BlockingDeque . class , RedissonBlockingDeque . class ) ;
supportedClassMapping . put ( Deque . class , RedissonDeque . class ) ;
supportedClassMapping . put ( BlockingQueue . class , RedissonBlockingQueue . class ) ;
supportedClassMapping . put ( Queue . class , RedissonQueue . class ) ;
supportedClassMapping . put ( List . class , RedissonList . class ) ;
SUPPORTED_CLASS_MAPPING . put ( SortedSet . class , RedissonSortedSet . class ) ;
SUPPORTED_CLASS_MAPPING . put ( Set . class , RedissonSet . class ) ;
SUPPORTED_CLASS_MAPPING . put ( ConcurrentMap . class , RedissonMap . class ) ;
SUPPORTED_CLASS_MAPPING . put ( Map . class , RedissonMap . class ) ;
SUPPORTED_CLASS_MAPPING . put ( BlockingDeque . class , RedissonBlockingDeque . class ) ;
SUPPORTED_CLASS_MAPPING . put ( Deque . class , RedissonDeque . class ) ;
SUPPORTED_CLASS_MAPPING . put ( BlockingQueue . class , RedissonBlockingQueue . class ) ;
SUPPORTED_CLASS_MAPPING . put ( Queue . class , RedissonQueue . class ) ;
SUPPORTED_CLASS_MAPPING . put ( List . class , RedissonList . class ) ;
}
private final Config config ;
@ -98,16 +98,16 @@ public class RedissonObjectBuilder {
}
}
private static final Map < Class < ? > , CodecMethodRef > references = new HashMap < Class < ? > , CodecMethodRef > ( ) ;
private static final Map < Class < ? > , CodecMethodRef > REFERENCES = new HashMap < > ( ) ;
private final ReferenceCodecProvider codecProvider = new DefaultReferenceCodecProvider ( ) ;
public RedissonObjectBuilder ( Config config ) {
super ( ) ;
this . config = config ;
fillCodecMethods ( references , RedissonClient . class , RObject . class ) ;
fillCodecMethods ( references , RedissonReactiveClient . class , RObjectReactive . class ) ;
fillCodecMethods ( references , RedissonRxClient . class , RObjectRx . class ) ;
fillCodecMethods ( REFERENCES , RedissonClient . class , RObject . class ) ;
fillCodecMethods ( REFERENCES , RedissonReactiveClient . class , RObjectReactive . class ) ;
fillCodecMethods ( REFERENCES , RedissonRxClient . class , RObjectRx . class ) ;
}
public ReferenceCodecProvider getReferenceCodecProvider ( ) {
@ -169,7 +169,7 @@ public class RedissonObjectBuilder {
}
private Class < ? extends RObject > getMappedClass ( Class < ? > cls ) {
for ( Entry < Class < ? > , Class < ? extends RObject > > entrySet : supportedClassMapping . entrySet ( ) ) {
for ( Entry < Class < ? > , Class < ? extends RObject > > entrySet : SUPPORTED_CLASS_MAPPING . entrySet ( ) ) {
if ( entrySet . getKey ( ) . isAssignableFrom ( cls ) ) {
return entrySet . getValue ( ) ;
}
@ -216,16 +216,17 @@ public class RedissonObjectBuilder {
ReferenceCodecProvider codecProvider )
throws IllegalAccessException , InvocationTargetException , Exception , ClassNotFoundException {
if ( type ! = null ) {
CodecMethodRef b = references . get ( type ) ;
CodecMethodRef b = REFERENCES . get ( type ) ;
if ( b = = null & & type . getInterfaces ( ) . length > 0 ) {
type = type . getInterfaces ( ) [ 0 ] ;
}
b = references . get ( type ) ;
b = REFERENCES . get ( type ) ;
if ( b ! = null ) {
Method builder = b . get ( isDefaultCodec ( rr ) ) ;
return ( isDefaultCodec ( rr )
? builder . invoke ( redisson , rr . getKeyName ( ) )
: builder . invoke ( redisson , rr . getKeyName ( ) , codecProvider . getCodec ( rr . getCodecType ( ) ) ) ) ;
if ( isDefaultCodec ( rr ) ) {
return builder . invoke ( redisson , rr . getKeyName ( ) ) ;
}
return builder . invoke ( redisson , rr . getKeyName ( ) , codecProvider . getCodec ( rr . getCodecType ( ) ) ) ;
}
}
throw new ClassNotFoundException ( "No RObject is found to match class type of " + rr . getTypeName ( ) + " with codec type of " + rr . getCodecName ( ) ) ;
@ -259,7 +260,7 @@ public class RedissonObjectBuilder {
if ( object instanceof RObject & & ! ( object instanceof RLiveObject ) ) {
Class < ? > clazz = object . getClass ( ) . getInterfaces ( ) [ 0 ] ;
RObject rObject = ( ( RObject ) object ) ;
RObject rObject = ( RObject ) object ;
if ( rObject . getCodec ( ) ! = null ) {
codecProvider . registerCodec ( ( Class ) rObject . getCodec ( ) . getClass ( ) , rObject . getCodec ( ) ) ;
}
@ -268,7 +269,7 @@ public class RedissonObjectBuilder {
if ( object instanceof RObjectReactive & & ! ( object instanceof RLiveObject ) ) {
Class < ? > clazz = object . getClass ( ) . getInterfaces ( ) [ 0 ] ;
RObjectReactive rObject = ( ( RObjectReactive ) object ) ;
RObjectReactive rObject = ( RObjectReactive ) object ;
if ( rObject . getCodec ( ) ! = null ) {
codecProvider . registerCodec ( ( Class ) rObject . getCodec ( ) . getClass ( ) , rObject . getCodec ( ) ) ;
}
@ -296,14 +297,24 @@ public class RedissonObjectBuilder {
public < T extends RObject , K extends Codec > T createRObject ( RedissonClient redisson , Class < T > expectedType , String name , K codec ) throws Exception {
List < Class < ? > > interfaces = Arrays . asList ( expectedType . getInterfaces ( ) ) ;
for ( Class < ? > iType : interfaces ) {
if ( references . containsKey ( iType ) ) { // user cache to speed up things a little.
Method builder = references . get ( iType ) . get ( codec ! = null ) ;
return ( T ) ( codec ! = null
? builder . invoke ( redisson , name )
: builder . invoke ( redisson , name , codec ) ) ;
if ( REFERENCES . containsKey ( iType ) ) { // user cache to speed up things a little.
Method builder = REFERENCES . get ( iType ) . get ( codec ! = null ) ;
if ( codec ! = null ) {
return ( T ) builder . invoke ( redisson , name ) ;
}
return ( T ) builder . invoke ( redisson , name , codec ) ;
}
}
String type = null ;
if ( expectedType ! = null ) {
type = expectedType . getName ( ) ;
}
String codecName = null ;
if ( codec ! = null ) {
codecName = codec . getClass ( ) . getName ( ) ;
}
throw new ClassNotFoundException ( "No RObject is found to match class type of " + ( expectedType ! = null ? expectedType . getName ( ) : "null" ) + " with codec type of " + ( codec ! = null ? codec . getClass ( ) . getName ( ) : "null" ) ) ;
throw new ClassNotFoundException ( "No RObject is found to match class type of " + type + " with codec type of " + codec Name) ;
}
}