2929// Redis imports
3030import org .redisson .Redisson ;
3131import org .redisson .client .codec .StringCodec ;
32+ import org .redisson .codec .JsonJacksonCodec ;
3233import org .redisson .api .RedissonClient ;
3334import org .redisson .api .RMap ;
3435import org .redisson .api .RKeys ;
@@ -78,7 +79,7 @@ public Redis_DataObjectMap(RedisStack inStack, String name) {
7879 super ();
7980 redisStack = inStack ;
8081 redisson = inStack .getConnection ();
81- redisMap = redisson .getMap (name , StringCodec .INSTANCE );
82+ redisMap = redisson .getMap (name , JsonJacksonCodec .INSTANCE );
8283 //set = redisson.getSet(name, StringCodec.INSTANCE);
8384 }
8485
@@ -125,7 +126,7 @@ protected RMap<String, Map<String, Object>> backendMap() {
125126 if (_backendRMap != null ) {
126127 return _backendRMap ;
127128 }
128- _backendRMap = redisson .getMap (name (), StringCodec .INSTANCE );
129+ _backendRMap = redisson .getMap (name (), JsonJacksonCodec .INSTANCE );
129130 return _backendRMap ;
130131 }
131132
@@ -192,12 +193,11 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
192193
193194 // call the default implementation, basically equal to redisMap.put(_oid,clonedMap)
194195 super .DataObjectRemoteDataMap_update (_oid , clonedMap , updateKeys );
195-
196- //Print map slice for the _oid
197- // Set<String> keys = new HashSet<String>();
198- // keys.add(_oid);
199- // Map<String, Object> mapSlice = redisMap.getAll(keys);
200- // System.out.println(mapSlice);
196+ }
197+
198+ public Map <String ,Object > ObjToMap (Object resObj ) {
199+ if ( resObj instanceof Map ) { return (Map <String ,Object >) resObj ; }
200+ else {return null ;}
201201 }
202202
203203 /**
@@ -206,48 +206,38 @@ public void DataObjectRemoteDataMap_update(String _oid, Map<String, Object> full
206206 **/
207207 public Map <String , Object > DataObjectRemoteDataMap_get (String _oid ) {
208208
209- Collection <Object > res = redisMap .values (_oid );
209+ //Map Slicing
210+ Set <String > keys = new HashSet <String >();
211+ keys .add (_oid );
212+ Map <String , Object > mapSlice = redisMap .getAll (keys );
213+
214+ Map .Entry <String ,Object > res = mapSlice .entrySet ().iterator ().next ();
215+ Object tmpObj = res .getValue ();
210216
211- Object resObj = res .iterator ().next ();
212- if (resObj == null ) {
217+ if (tmpObj == null ) {
213218 return null ;
214219 }
215220
216- //Convert resObj to String
217- String resString = resObj .toString ();
218- //Get rid of {}
219- resString = resString .substring (1 , resString .length () - 1 );
221+ Map <String , Object > resObj = null ;
222+ resObj = ObjToMap (tmpObj );
220223
221- //Convert resString to Map
222- //if duplicate keys show up, the first one encountered takes precedence
223- //for latest value for a duplicate key then use (a, b)-> b as the merge lambda.)
224- Map <String , Object > resMap = Arrays .stream (resString .split ("," ))
225- .map (str -> str .split ("=" ))
226- .collect (Collectors .toMap (a -> a [0 ], a ->a [1 ], (a , b ) -> a ));
227-
228-
229- //Convert resObj to String so I can use replace() to make it a valid hjson
230- //https://github.com/hjson/hjson-java
231- // String tmpString=resObj.toString();
232- // tmpString=tmpString.replace('=',':');
233- // System.out.println(resObj);
234- // Map<String, String> mapData = GenericConvert.toStringMap(resObj);
235- // System.out.println(mapData);
224+ System .out .println (resObj );
225+ System .out .println (resObj instanceof Map );
236226
237227 Map <String , Object > ret = new HashMap <>();
238228
239229 // Lets iterate through the object
240- Set <String > fullKeys = resMap .keySet ();
230+ Set <String > fullKeys = resObj .keySet ();
241231 for (String key : fullKeys ) {
242232
243233 // Get the value
244- Object val = resMap .get (key );
234+ Object val = resObj .get (key );
245235
246236 // Populate the ret map
247237 ret .put (key , val );
248238 }
249239
250- return ret ;
240+ return ret = null ;
251241 }
252242
253243 // /**
@@ -298,46 +288,46 @@ public void DataObjectRemoteDataMap_remove(String _oid) {
298288 *
299289 * @return The String[] array
300290 **/
301- // public String[] query_id(Query queryClause, String orderByStr, int offset, int limit) {
291+ public String [] query_id (Query queryClause , String orderByStr , int offset , int limit ) {
302292
303- // // The return list of DataObjects
304- // List<String> retList = null;
293+ // The return list of DataObjects
294+ List <String > retList = null ;
305295
306- // RMap<String, Object> myRedisMap = redisMap;
296+ RMap <String , Object > myRedisMap = redisMap ;
307297
308- // // Setup the query, if needed
309- // if (queryClause == null) {
310- // // Null gets all
311- // retList = new ArrayList<String>(myRedisMap.readAllKeySet());
312- // } else {
298+ // Setup the query, if needed
299+ if (queryClause == null ) {
300+ // Null gets all
301+ retList = new ArrayList <String >(myRedisMap .readAllKeySet ());
302+ } else {
313303
314- // // Get the list of _oid that passes the query
315- // //Set<String> idSet = backendIMap().keySet(queryPredicate);
316- // //String[] idArr = idSet.toArray(new String[0]);
304+ // Get the list of _oid that passes the query
305+ //Set<String> idSet = backendIMap().keySet(queryPredicate);
306+ //String[] idArr = idSet.toArray(new String[0]);
317307
318- // // DataObject[] from idArr
319- // //DataObject[] doArr = getArrayFromID(idArr, true);
308+ // DataObject[] from idArr
309+ //DataObject[] doArr = getArrayFromID(idArr, true);
320310
321- // // Converts to a list
322- // //retList = new ArrayList(Arrays.asList(doArr));
323- // retList = new ArrayList<String>(myRedisMap.readAllKeySet());
324- // }
311+ // Converts to a list
312+ //retList = new ArrayList(Arrays.asList(doArr));
313+ retList = new ArrayList <String >(myRedisMap .readAllKeySet ());
314+ }
325315
326- // // Sort, offset, convert to array, and return
327- // // ???
316+ // Sort, offset, convert to array, and return
317+ // ???
328318
329- // // Prepare the actual return string array
330- // int retLength = retList.size();
331- // String[] ret = new String[retLength];
332- // for (int a = 0; a < retLength; ++a) {
333- // //._oid(); -> where is it coming from
334- // //ret[a] = retList.get(a)._oid();
335- // ret[a] = String.valueOf(retList.get(a));
336- // }
319+ // Prepare the actual return string array
320+ int retLength = retList .size ();
321+ String [] ret = new String [retLength ];
322+ for (int a = 0 ; a < retLength ; ++a ) {
323+ //._oid(); -> where is it coming from
324+ //ret[a] = retList.get(a)._oid();
325+ ret [a ] = String .valueOf (retList .get (a ));
326+ }
337327
338- // System.out.println(Arrays.toString(ret));
339- // // Returns sorted array of strings
340- // return ret;
341- // }
328+ System .out .println (Arrays .toString (ret ));
329+ // Returns sorted array of strings
330+ return ret ;
331+ }
342332
343333}
0 commit comments